Android自定义不需要焦点的TextView以实现跑马灯效果
2016-11-28 11:15
861 查看
使用原生的TextView实现“跑马灯”效果,需要特别注意其是否获取到了焦点(特别是程序当中有多个需要赋值的
Textview或进度条之类的需要改变其值的View);TextView只有在获得了焦点的时候才有跑马灯的效果,这样有时候并
不能达到我们所要求的效果。我们可以自定义一个永远已经获取焦点的TextView。
具体代码如下所示。
将自定义的AmMarqueeTextView放到布局文件中,如下所示。
Textview或进度条之类的需要改变其值的View);TextView只有在获得了焦点的时候才有跑马灯的效果,这样有时候并
不能达到我们所要求的效果。我们可以自定义一个永远已经获取焦点的TextView。
具体代码如下所示。
package com.example.view; import android.content.Context; import android.util.AttributeSet; import android.view.ViewDebug.ExportedProperty; import android.widget.TextView; public class AmMarqueeTextView extends TextView { public AmMarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public AmMarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public AmMarqueeTextView(Context context, AttributeSet attrs) { super(context, attrs); } @Override @ExportedProperty(category = "focus") public boolean isFocused() { return true; } }
将自定义的AmMarqueeTextView放到布局文件中,如下所示。
<cn.net.ample.music.view.AmMarqueeTextView android:id="@+id/tv_music_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:text="@string/tip_music_name" android:textColor="@color/grass_green" android:textSize="@dimen/current_theme_text_size" />
相关文章推荐
- android TextView不用获得焦点实现跑马灯效果 两种方法
- Android中TextView不获取焦点可以实现跑马灯的效果
- Android中TextView不获取焦点可以实现跑马灯的效果
- Android的自定义TextView实现跑马灯效果
- android自定义的TextView,实现跑马灯效果
- Android:TextView不获取焦点可以实现跑马灯的效果
- Android自定义TextView实现跑马灯效果
- Android自定义textview实现竖直滚动跑马灯效果
- Android基于TextView不获取焦点实现跑马灯效果
- Android中TextView不获取焦点可以实现跑马灯的效果
- Android中TextView不获取焦点可以实现跑马灯的效果
- Android重写TextView实现文字跑马灯效果
- android用TextView实现跑马灯效果
- TextView属性android:ellipsize实现跑马灯效果
- Android实现多个跑马灯效果,多个文本框TextView的跑马灯
- Android之TextView内容实现跑马灯效果
- Android TextView实现跑马灯效果
- Android开发 TextView实现跑马灯效果
- android TextView实现实现跑马灯效果,并监听滚动完成动作。
- android 倒计时、有清除功能编辑框、popupwindow、跑马灯效果实现(基于TextView)