尝试从数组填充文本视图。我通过下面的代码设法通过 XML 获得了所需的效果
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/marque_scrolling_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:padding="16dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Create a Marquee (Scrolling Text) in Android Using TextView. Android Marquee (Scrolling Text) Tutorial with Example"
android:textSize="24sp" />
</LinearLayout>
但我需要将其中的几个放在一个数组中 - 所以我相信以编程方式创建文本视图可能是答案,但无法将它们置于字幕中。这是我正在处理的代码。
String[] strings = {"Mark", "James", "Paul"};
LinearLayout layout = (LinearLayout)findViewById(R.id.linearlayout);
for(String s : strings)
{
TextView newTextView = new TextView(this);
newTextView.setText(s);
newTextView.setSingleLine(true);
newTextView.setEllipsize(TextUtils.TruncateAt.END);
newTextView.setHorizontallyScrolling(true);
newTextView.setLines(1);
newTextView.setMarqueeRepeatLimit(-1);
newTextView.setSelected(true);
newTextView.setTextSize(24);
layout.addView(newTextView);
}
试试这个..它有效
TextView testing = (TextView) this.findViewById(R.id.testing);
testing.setEllipsize(TextUtils.TruncateAt.MARQUEE);
testing.setMarqueeRepeatLimit(-1);
testing.setSingleLine(true);
testing.setSelected(true);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)