是否有可能为TextView的字幕在一个Widget扩展AppWidgetProvider? [英] Is it possible for TextView Marquee in a Widget that extends AppWidgetProvider?

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

问题描述

我很新到Android编程,我已经阅读无处不在,我似乎无法找到任何解决方案。

基本的问题是,我有一个TextView的一个构件,我想滚动文本为长于的TextView layout_width的文本。这是我的code在layout_widget.xml

 < TextView的机器人:ID =@ + ID /事实上的Android:layout_width =200dp
            机器人:文本=载入中...详细文本,看看它跨越与否,并希望更多的
            机器人:单线=真
            机器人:ellipsize =金字招牌
            机器人:marqueeRepeatLimit =marquee_forever
            机器人:scrollHorizo​​ntally =真
            机器人:可聚焦=真
            机器人:focusableInTouchMode =真/>
 

现在,我读了我必须做的TextView是焦点,这是我做的事。我也看过,你需要设置的属性的setSelected(真),而这正是我努力设置。在我的默认的活动(在AndroidManifest.xml)我这下code。

  @覆盖
            公共无效的onCreate(包savedInstanceState){
                super.onCreate(savedInstanceState);
                的setContentView(R.layout.widget_layout);
                findViewById(R.id.fact).setSelected(真正的);
                的setContentView(R.layout.main);
            }
 

下面的部分是用来设置内容为widget_layout.xml,然后设置TextView的属性的setSelected为true

 的setContentView(R.layout.widget_layout);
                findViewById(R.id.fact).setSelected(真正的);
 

我然后返回的内容查看返回的main.xml

现在我猜这是不对的,这是没有办法的办法,应该做的。但我想知道,如果是可以做到的。我也看到,如果你可以重写框架,你可以把你自己的属性,例如滚动型,这是正确的呢?另外,我在SDK版本7。

我多少AP preciate的帮助下,我收到,谢谢大家!

编辑:通过去除的的setContentView(R.layout.main); 的通过应用牵引启动应用程序时,该文中滚动,但小部件不。那种使我的一个小部件不能有字幕???有没有人有一个字幕工作的一个小部件??

EDIT2:解决。这是它是如何做

在XML文本查看您需要有一个标签这基本上我觉得是一样的getSeleted(真);

所以,code应该如下:

 < TextView的机器人:ID =@ + ID /事实上的Android:layout_width =200dp
            机器人:文本=载入中...详细文本,看看它跨越与否,并希望更多的
            机器人:单线=真
            机器人:ellipsize =金字招牌
            机器人:marqueeRepeatLimit =marquee_forever
            机器人:scrollHorizo​​ntally =真
            机器人:可聚焦=真
            机器人:focusableInTouchMode =真
            机器人:duplicateParentState =真正的>
        < requestFocus的机器人:可调焦=真正的机器人:focusableInTouchMode =真
            机器人:duplicateParentState =真/>
    < / TextView的>
 

解决方案

解决。这是它是如何做

在XML文本查看您需要有一个标签这基本上我觉得是一样的getSeleted(真);

所以,code应该如下:

 < TextView的机器人:ID =@ + ID /事实上的Android:layout_width =200dp
        机器人:文本=载入中...详细文本,看看它跨越与否,并希望更多的
        机器人:单线=真
        机器人:ellipsize =金字招牌
        机器人:marqueeRepeatLimit =marquee_forever
        机器人:scrollHorizo​​ntally =真
        机器人:可聚焦=真
        机器人:focusableInTouchMode =真
        机器人:duplicateParentState =真正的>
    < requestFocus的机器人:可调焦=真正的机器人:focusableInTouchMode =真
        机器人:duplicateParentState =真/>
< / TextView的>
 

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

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

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

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

I then return the ContentView back to main.xml

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!

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

In the xml for the text view you need to have a tag This basically I think is the same as getSeleted(true);

So the code should be as followed:

    <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

In the xml for the text view you need to have a tag This basically I think is the same as getSeleted(true);

So the code should be as followed:

<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的字幕在一个Widget扩展AppWidgetProvider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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