Android textView 滚动

来源:互联网 发布:淘宝贷款额度可以作假 编辑:程序博客网 时间:2024/05/21 22:55

Textvie滚动效果

1.第一种方式    <!--         singleLine : 一行显示        ellipsize              none :省略后面文字            start : 隐藏前面的文字            middle : 隐藏中间的文字            end : 隐藏后面的文字            marquee : 滚动        focusableInTouchMode : 触摸获取焦点        TextView天生是没有点击事件和获取焦点的事件        focusable : 是否获取焦点操作,true:可以  false:不可以        marqueeRepeatLimit : 设置滚动次数,marquee_forever : -1  一直滚动    -->    <TextView         android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="aaassss"        android:singleLine="true"        android:ellipsize="marquee"        android:focusableInTouchMode="true"        android:focusable="true"        android:marqueeRepeatLimit="marquee_forever"        />2.第二种方式,自定义一个textview,让textview自动获取焦点    a.创建自定义控件,继承textview        public class HomeTextView extends TextView {            //在代码中使用的调用            public HomeTextView(Context context) {                super(context);            }            //在布局文件中使用的时候调用,比两个参数多了样式            public HomeTextView(Context context, AttributeSet attrs, int defStyle) {                super(context, attrs, defStyle);                // TODO Auto-generated constructor stub            }            //在布局文件中使用的时候调用            //布局文件中的控件都是可以用代码来表示            //AttributeSet : 保存了控件在布局文件中的所有属性            public HomeTextView(Context context, AttributeSet attrs) {                super(context, attrs);                // TODO Auto-generated constructor stub            }            //设置自定义的textview自动获取焦点            //是否获取焦点            @Override            public boolean isFocused() {                //true:获取焦点,false:不获取焦点                return true;            }        }    b.再布局文件中使用        <com.itheima.mobliesafe75.ui.HomeTextView             android:layout_width="match_parent"            android:layout_height="wrap_content"            android:text="1112223333"            android:singleLine="true"            android:ellipsize="marquee"            android:focusableInTouchMode="true"            android:marqueeRepeatLimit="marquee_forever"            />
0 0
原创粉丝点击