安卓学习:跑马灯遇到的问题

来源:互联网 发布:网络流行语2016我好饿 编辑:程序博客网 时间:2024/06/11 05:10

学习了textview的跑马灯效果,按照教程增加了以下属性:

android:ellipsize="marquee"android:focusable="true"android:focusableInTouchMode="true"

运行后发现文字依然不动,后来才明白,由于我是在一个parent组件中练习,父节点中存在多个控件,上面有两个输入框和一个按钮,这样的话进来的时候焦点就不会落在跑马灯的textview对象上,因此无法触发滚动。

按照网上的帮助,自定义一个类,实现isFocused方法为true,再在activity_main.xml中修改节点如下:

<com.example.demo1.Marquee        android:id="@+id/textView4"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@+id/textView3"        android:ellipsize="marquee"        android:focusable="true"        android:focusableInTouchMode="true"        android:singleLine="true"        android:text="@string/txtV_3"         />

这样,既可以避免失去焦点的问题,也可以同时增加多个跑马灯控件效果。

0 0