为什么字幕不工作在工具? [英] Why Is Marquee Not Working In Widget?

查看:142
本文介绍了为什么字幕不工作在工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个小白到Android和我试图创建一个使用TextView的滚动字幕显示鸣叫在股票时尚小部件。当我在XML中的小部件设置文本字幕滚动正常。然而,当我试图设置文本编程选取框不滚动。文字设定,但它只是不滚动。这种行为令人费解,因为我使用的<一个href=\"http://stackoverflow.com/questions/7868748/is-it-possible-for-textview-marquee-in-a-widget-that-extends-appwidgetprovider\">this SO质疑我的指导。任何帮助是极大的AP preciated。

我的布局

 &LT;的TextView
        机器人:ID =@ + ID /股票
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentRight =真
        机器人:duplicateParentState =真
        机器人:ellipsize =金字招牌
        机器人:fadingEdge =横向
        机器人:可聚焦=真
        机器人:focusableInTouchMode =真
        机器人:行=1
        机器人:marqueeRepeatLimit =marquee_forever
        机器人:scrollHorizo​​ntally =真
        机器人:文字=简单的应用程序,展示了如何使用帐篷,用长文本的Twitter频道&GT; //&LT; - 这段文字滚动罚款        &LT; requestFocus的
            机器人:duplicateParentState =真
            机器人:可聚焦=真
            机器人:focusableInTouchMode =真/&GT;
    &LT; / TextView的&GT;

我的code

 公共静态无效updateAppWidget(上下文的背景下,AppWidgetManager appWidgetManager,诠释appWidgetId){
    //字符串currentTime的= df.format(新的Date());
    串现货黄金=将String.valueOf(MyActivity.widgetlivespotgold);
    字符串spotsilver =将String.valueOf(MyActivity.widgetlivespotsilver);
    StringBuilder的tickertweets =新的StringBuilder();
    的for(int i = 0; I&LT; MyActivity.twittername.size();我++){
        tickertweets.append(MyActivity.twittername.get(I)+:++ MyActivityActivity.twittertweet.get(I)+);
    }
    RemoteViews updateViews =新的RemoteViews(context.getPackageName(),R.layout.widget1);    updateViews.setTextViewText(R.id.goldspot,现货黄金);
    updateViews.setTextViewText(R.id.silverspot,spotsilver);
    updateViews.setTextViewText(R.id.ticker,tickertweets.toString()); //文本被设置,但不会滚动
    appWidgetManager.updateAppWidget(appWidgetId,updateViews);
}


解决方案

请务必使用的android:单线=真正的的android: scrollHorizo​​ntally =FALSE在XML(或完全删除)。这应该做的伎俩。

I am a noob to android and I am trying to create a widget that uses textview marquee to displays tweets in a ticker fashion. When I set the text in the xml the marquee scrolls properly in the widget. However, when i attempt to set the text programmatically the marquee doesn't scroll. The text is set, but it just doesn't scroll. This behavior is baffling because i used this SO question as my guide. Any help is greatly appreciated.

My Layout

<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>

My Code

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);
}

解决方案

Make sure to use android:singleLine="true" and android:scrollHorizontally="false" (or remove it completely) in your XML. This should do the trick.

这篇关于为什么字幕不工作在工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆