Android 是否可以在扩展AppWidgetProvider的小部件中使用TextView字幕?

Android 是否可以在扩展AppWidgetProvider的小部件中使用TextView字幕?,android,android-widget,widget,textview,marquee,Android,Android Widget,Widget,Textview,Marquee,我对Android编程非常陌生,我到处都读过,似乎找不到任何解决方案 基本问题是,我在一个小部件中有一个TextView,我希望文本在长度超过TextView布局宽度时滚动。这是我在layout_widget.xml中的代码 <TextView android:id="@+id/fact" android:layout_width="200dp" android:text="Loading... More text to see if it spans or

我对Android编程非常陌生,我到处都读过,似乎找不到任何解决方案

基本问题是,我在一个小部件中有一个TextView,我希望文本在长度超过TextView布局宽度时滚动。这是我在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" />
下面的部分用于将内容设置为widget_layout.xml,然后将setSelected的TextView属性设置为true

                setContentView(R.layout.widget_layout);
                findViewById(R.id.fact).setSelected(true);
然后,我将ContentView返回main.xml

现在我猜这是错误的,这不是应该做的。但我想知道是否可以做到。我还了解到,如果您可以覆盖框架,您可以将自己的属性放入,例如ScrollView,这对吗?我也在SDK版本7上

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

编辑:删除setContentView(R.layout.main);通过app draw启动应用程序时,文本会滚动,但小部件不会。有点让我觉得小部件不能有字幕???有人在小部件上有字幕吗

Edit2:已解决。就是这样做的

在文本视图的xml中,您需要有一个标记,我认为这基本上与getSeletd(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>
<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>

您正在调用
setContentView
两次:

setContentView(R.layout.widget_layout);
findViewById(R.id.fact).setSelected(true);
setContentView(R.layout.main);

您的活动只能有一个布局。如果
widget\u布局
是包含文本视图的widget布局,那么您不希望第二个
setContentView

问题得到解决。就是这样做的

在文本视图的xml中,您需要有一个标记,我认为这基本上与getSeletd(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>
<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>


欢迎使用堆栈溢出!如果有人解决了你的问题,请记住接受答案。干杯,但解决方案不起作用。这真的对你有效吗?因为我不能让它工作…它工作。但若小部件有两个文本视图,那个么只有一个文本视图在滚动。。。如何滚动所有文本视图?
requestFocus
部分必须读取
是的,我知道。根据我的理解(我可能会说,这可能是错误的),当您单击应用程序绘图上的应用程序时,将打开链接到AndroidManifest的活动。现在在这个活动中,我希望它使用main.xml。我遇到的问题是,我需要使用一个活动类,其中调用onCreate(),它查看layout_widget.xml内容。这就是为什么我首先调用layout_小部件,以便设置layout_小部件的属性,然后将其恢复为内容。我知道这听起来不对,但我不知道怎么做…嗨,我解决了这个问题。邮寄。在上面的帖子上编辑这是如何实现的。这非常有效!然而,它破坏了我的点击事件,我的文本视图在RelativeLayout中与ImageView重叠。有没有办法解决这个问题?不太确定,也许你得限制尺寸。