我是 android 的菜鸟,我正在尝试创建一个小部件,它使用 textview marquee 以自动收报机方式显示推文。当我在 xml 中设置文本时,选取框在小部件中正确滚动。但是,当我尝试以编程方式设置文本时,选取框不会滚动。文本已设置,但它只是不滚动。这种行为令人费解,因为我使用这个SO 问题作为我的指导。任何帮助是极大的赞赏。
我的布局
<TextView
android:id="@+id/ticker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:duplicateParentState="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:focusable="true"
android:focusableInTouchMode="true"
android:lines="1"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:text="Simple application that shows how to use marquee, with a long text for Twitter Feed" > //<--this text scrolls fine
<requestFocus
android:duplicateParentState="true"
android:focusable="true"
android:focusableInTouchMode="true" />
</TextView>
我的代码
public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
//String currentTime = df.format(new Date());
String spotgold = String.valueOf(MyActivity.widgetlivespotgold);
String spotsilver = String.valueOf(MyActivity.widgetlivespotsilver);
StringBuilder tickertweets=new StringBuilder();
for (int i = 0; i < MyActivity.twittername.size(); i++) {
tickertweets.append(MyActivity.twittername.get(i) + ":" + " " + MyActivityActivity.twittertweet.get(i) + " ");
}
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.widget1);
updateViews.setTextViewText(R.id.goldspot, spotgold);
updateViews.setTextViewText(R.id.silverspot, spotsilver);
updateViews.setTextViewText(R.id.ticker, tickertweets.toString()); //Text is set, but doesn't scroll
appWidgetManager.updateAppWidget(appWidgetId, updateViews);
}