首先我们在Xml中定义一个TextView的控件
ellipsize=start为开始为...
ellipsize=end为最后...
ellipsize=marquee为以跑马灯的形式
<TextView
android:ellipsize="start" 首先我们在定义ellipsize时为start也不会在前面显示.....只有加上只有一行的属性singleLine为true才可以显示
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="你需要的版本立即升级 尽请期待中!!!下载送更多的礼品,你需要的版本立即升级 尽请期待中!!!下载送更多的礼品"
/>
改进如果我们把它改为Button控件(Button控件天生就有滚动的属性)
<Button
android:focusableInTouchMode="true" 设置成Button的滚动属性
android:ellipsize="start"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="你需要的版本立即升级 尽请期待中!!!下载送更多的礼品,你需要的版本立即升级 尽请期待中!!!下载送更多的礼品"
/>
可是我们的需求不是Button按钮的效果 (这时候我们想把TextView天上下来就有Button属性的自定滚动)
这时候我们就开始创建自定义TextVeiw的包com.bawei.ui 实体类为FocusedTextView 然后继承TextView的类
实现我们TextView中的三个方法
/
*自定义一个TextView的
让他自身有自己的焦点
*/
public FocusedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public FocusedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public FocusedTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
然后我们在创建出来存在焦点的方法
@Override
@ExportedProperty(category = "focus")
public boolean isFocused() {
// TODO Auto-generated method stub
在isFocused中的父控件的源码标记判断是否有焦点 如果有焦点就返回true
这时候我们不管他有没有焦点都让他返回true return true;
return super.isFocused();
}
然后在我们FocusedTextView中 Copy Qualified Name把它放到TextView的控件中
<com.example.TextSchool.Ui.FocusedTextView
android:ellipsize="marquee"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="你需要的版本立即升级 尽请期待中!!!下载送更多的礼品,你需要的版本立即升级 尽请期待中!!!下载送更多的礼品"
/>
这样就完成了我们的自定义我们TextView的滚动