Java代码包装html文本装入Android TextView实现跑马灯
String html = "<font color=\"#436EEE\">▰</font><font color=\"#6495ED\">▰</font><font color=\"#CAE1FF\">▰</font>";
String ss = "";
for (int i = 0; i < 100; i++) {
ss = ss + html;
}
TextView textView = findViewById(R.id.text);
if (textView != null) {
Spanned spanned = Html.fromHtml(ss, Html.FROM_HTML_MODE_COMPACT);
textView.setText(spanned);
textView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
textView.setSingleLine(true);
textView.setSelected(true);
}
至于xml布局里面的TextView非常简单:
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold" />