扩展AppWidgetProvider的Widget中的TextView Marquee是否可能?

Spr*_*ngy 13 android widget marquee textview android-widget

我是Android编程的新手,我到处都读过,我似乎无法找到任何解决方案.

基本问题是我在一个小部件中有一个TextView,我希望文本在文本长于TextView layout_width时滚动.这是我在layout_widget.xml中的代码

    <TextView android:id="@+id/fact" android:layout_width="200dp"
            android:text="Loading... More text to see if it spans or not and want more"
            android:singleLine="true" 
            android:ellipsize="marquee"
            android:marqueeRepeatLimit ="marquee_forever"
            android:scrollHorizontally="true"
            android:focusable="true"
            android:focusableInTouchMode="true" />
Run Code Online (Sandbox Code Playgroud)

现在我读到我必须让TextView成为焦点,我已经完成了.我还读过你需要设置属性setSelected(true),这是我努力设置的地方.在我的默认Activity(在AndroidManifest.xml中)中,我有以下代码.

            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.widget_layout);
                findViewById(R.id.fact).setSelected(true);
                setContentView(R.layout.main);
            }
Run Code Online (Sandbox Code Playgroud)

下面的部分用于将Content设置为widget_layout.xml,然后将setSelected的TextView属性设置为true

                setContentView(R.layout.widget_layout);
                findViewById(R.id.fact).setSelected(true);
Run Code Online (Sandbox Code Playgroud)

然后我将ContentView返回给main.xml

现在我猜这是错的,这不是它应该做的方式.但我想知道是否可以做到.我还读到,如果你可以覆盖框架,你可以把你自己的属性,例如ScrollView,这也是正确的吗?我也在使用SDK Version 7.

非常感谢我收到的帮助,谢谢大家!

编辑:删除setContentView(R.layout.main); 当通过应用程序绘制启动应用程序时,文本会滚动,但小部件不会.有点让我知道一个小部件不能有一个选框??? 有没有人在一个小工具上工作?

编辑2:解决了.这就是它的完成方式

在文本视图的xml中你需要有一个标签这基本上我认为与getSeleted(true)相同;

所以代码应该如下:

    <TextView android:id="@+id/fact" android:layout_width="200dp"
            android:text="Loading... More text to see if it spans or not and want more"
            android:singleLine="true" 
            android:ellipsize="marquee"
            android:marqueeRepeatLimit ="marquee_forever"
            android:scrollHorizontally="true"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:duplicateParentState="true">
        <requestFocus android:focusable="true" android:focusableInTouchMode="true"
            android:duplicateParentState="true" />
    </TextView>
Run Code Online (Sandbox Code Playgroud)

Spr*_*ngy 28

解决了.这就是它的完成方式

在文本视图的xml中你需要有一个标签这基本上我认为与getSeleted(true)相同;

所以代码应该如下:

<TextView android:id="@+id/fact" android:layout_width="200dp"
        android:text="Loading... More text to see if it spans or not and want more"
        android:singleLine="true" 
        android:ellipsize="marquee"
        android:marqueeRepeatLimit ="marquee_forever"
        android:scrollHorizontally="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:duplicateParentState="true">
    <requestFocus android:focusable="true" android:focusableInTouchMode="true"
        android:duplicateParentState="true" />
</TextView>
Run Code Online (Sandbox Code Playgroud)