5
我有一個TexView
需要放置在格言2行,並有一個可鏈接的文本。 如果我將LinkMovementMethod設置爲文本視圖,我會得到一個可滾動的TextView
,並忽略橢圓大小。使橢圓化一個TextView有LinkMovementMethod
XML代碼:
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dip"
android:clickable="true"
android:maxLines="2"
android:ellipsize="end"
android:scrollHorizontally="false"
android:scrollbars="horizontal"
android:isScrollContainer="false"/>
這是我的活動:
public class MyActivity extends Activity {
private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.text_view);
SpannableStringBuilder captionSpan = new SpannableStringBuilder();
captionSpan.append("a very long text here a very long text here a very long text here a very long text here a very long text here a very long text here a very long text here a very long text here");
captionSpan.setSpan(new CustomClickableSpan(), 1, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(captionSpan);
tv.setMovementMethod(LinkMovementMethod.getInstance());
}
}
public class CustomClickableSpan extends android.text.style.ClickableSpan {
@Override
public void updateDrawState(TextPaint tp) {
tp.setColor(tp.linkColor);
tp.setUnderlineText(false);
}
@Override
public void onClick(View widget) {
}
}
如果我不設置移動方法一切工作正常。
我嚴重不知道該怎麼感謝你纔好!這救了我! – Cbr
我很高興幫助你) – Airfreshener
終於明白了..非常感謝你... –