扩展 AppWidgetProvider 的 Widget 中是否可以使用 TextView Marquee? [英] Is it possible for TextView Marquee in a Widget that extends AppWidgetProvider?

查看:11
本文介绍了扩展 AppWidgetProvider 的 Widget 中是否可以使用 TextView Marquee?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am very new to Android programming, and I have read everywhere and I can't seem to find any solution.

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

Basic problem is that I have a TextView in a widget and I would like the text to scroll when the text is longer than the TextView layout_width. This is my code in the 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" />

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

Now I read that I have to make the TextView to be on focus, which I have done. I have also read that you need to set the property setSelected(true), and this is where I am struggling to set. In my default Activity (in the AndroidManifest.xml) I have this following code.

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

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

The part below is used to set the Content to the widget_layout.xml and then set the TextView property for setSelected to true

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

然后我将 ContentView 返回到 main.xml

I then return the ContentView back to main.xml

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

Now I am guessing this is wrong and this is not the way it should be done. But I am wondering if it can be done. I also read that if you can override the Framework, you can put your own properties in, for example ScrollView, is this right as well? Also I am on SDK Version 7.

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

I much appreciate the help I receive, thanks all!

通过删除 setContentView(R.layout.main); 在通过应用程序绘制启动应用程序时,文本会滚动,但小部件不会.有点让我觉得小部件不能有选框???有没有人在一个小部件上做一个选取框??

By removing setContentView(R.layout.main); when launching the application via the app draw, the text does scroll, but the widget doesn't. Kind of leads me to that a widget cannot have a marquee??? Has anyone got a marquee working on a widget??

Edit2:已解决.这样做是这样的

Solved. This is how it is done

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

In the xml for the text view you need to have a tag This basically I think is the same as 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>

推荐答案

解决了.这样做是这样的

Solved. This is how it is done

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

In the xml for the text view you need to have a tag This basically I think is the same as 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>

这篇关于扩展 AppWidgetProvider 的 Widget 中是否可以使用 TextView Marquee?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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