我有一个需要放置在最多两行中并且其中的文本可以链接的 TexView
。
如果我将 LinkMovementMethod 设置为文本视图,我会得到一个可滚动的 TextView
,而省略号会被忽略。
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) {
}
}
如果我不设置移动方法,一切都正常工作。