android中TextView中如何设置水平滚动效果
2014-12-02 10:58
253 查看
Android系统中TextView实现跑马灯效果,必须具备以下几个条件:
1、android:ellipsize=”marquee”
2、TextView必须单行显示,即内容必须超出TextView大小
3、TextView要获得焦点才能滚动
XML代码:
android:ellipsize="marquee", android:singleLine="true"
Java代码:
mTVText.setText("哼唱接撒砥砺风节雷锋精神http://orgcent.com/,很长很长很长很长很长很长的数据");
mTVText.setSingleLine(true);
mTVText.setEllipsize(TruncateAt.MARQUEE);
PS: TextView.setHorizontallyScrolling(true); //让文字可以水平滑动
TextView还可以设置跑马灯效果的滚动次数,如下:
XML代码设置:
android:marqueerepeatlimit="1"。1代表1次,-1代表无限循环。
Java代码设置:
mTVText.setMarqueeRepeatLimit(-1);
转自http://www.cnblogs.com/top5/archive/2012/05/18/2507642.html
TextView实现文字滚动需要以下几个要点:
1.文字长度长于可显示范围:android:singleLine="true"
2.设置可滚到,或显示样式:android:ellipsize="marquee"
3.TextView只有在获取焦点后才会滚动显示隐藏文字,因此需要在包中新建一个类,继承TextView。重写isFocused方法,这个方法默认行为是,如果TextView获得焦点,方法返回true,失去焦点则返回false。跑马灯效果估计也是用这个方法判断是否获得焦点,所以把它的返回值始终设置为true。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/tv"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="15sp" />
</LinearLayout>
ellipsize属性
设置当文字过长时,该控件该如何显示。有如下值设置:”start”—–省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动)
marqueeRepeatLimit属性
在ellipsize指定marquee的情况下,设置重复滚动的次数,当设置为marquee_forever时表示无限次。
focusable属性
能否获得焦点,同样focusableInTouchMode应该是滑动时能否获得焦点。
转自http://chengbs.iteye.com/blog/1156136
1、android:ellipsize=”marquee”
2、TextView必须单行显示,即内容必须超出TextView大小
3、TextView要获得焦点才能滚动
XML代码:
android:ellipsize="marquee", android:singleLine="true"
Java代码:
mTVText.setText("哼唱接撒砥砺风节雷锋精神http://orgcent.com/,很长很长很长很长很长很长的数据");
mTVText.setSingleLine(true);
mTVText.setEllipsize(TruncateAt.MARQUEE);
PS: TextView.setHorizontallyScrolling(true); //让文字可以水平滑动
TextView还可以设置跑马灯效果的滚动次数,如下:
XML代码设置:
android:marqueerepeatlimit="1"。1代表1次,-1代表无限循环。
Java代码设置:
mTVText.setMarqueeRepeatLimit(-1);
转自http://www.cnblogs.com/top5/archive/2012/05/18/2507642.html
TextView实现文字滚动需要以下几个要点:
1.文字长度长于可显示范围:android:singleLine="true"
2.设置可滚到,或显示样式:android:ellipsize="marquee"
3.TextView只有在获取焦点后才会滚动显示隐藏文字,因此需要在包中新建一个类,继承TextView。重写isFocused方法,这个方法默认行为是,如果TextView获得焦点,方法返回true,失去焦点则返回false。跑马灯效果估计也是用这个方法判断是否获得焦点,所以把它的返回值始终设置为true。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/tv"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="15sp" />
</LinearLayout>
ellipsize属性
设置当文字过长时,该控件该如何显示。有如下值设置:”start”—–省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动)
marqueeRepeatLimit属性
在ellipsize指定marquee的情况下,设置重复滚动的次数,当设置为marquee_forever时表示无限次。
focusable属性
能否获得焦点,同样focusableInTouchMode应该是滑动时能否获得焦点。
转自http://chengbs.iteye.com/blog/1156136
相关文章推荐
- android中TextView中如何设置水平滚动效果
- android中TextView中如何设置水平滚动效果
- android中TextView中如何设置水平滚动效果
- android中TextView中如何设置水平滚动效果
- android 如何让appwidget 里面设置TextView 滚动,android widget marquee text
- Android textview和listview实现水平自动滚动的走马灯效果
- android 设置TextView水平滚动和解决首行缩进问题
- Android之如何用TextView实现滚动字幕的效果【跑马灯】
- Android中TextView如何实现水平和垂直滚动
- Android TextView实现水平滚动显示效果
- Android开发之TextView文字水平滚动效果实现
- Android开发中如何给EditText设置多行效果
- android中TextView中文本滚动的跑马灯效果
- TextView 实现走马观灯 水平滚动效果
- android中设置TextView/Button 走马灯效果
- Android组件TextView实现字体水平滚动
- android textview 跑马灯 滚动效果
- android textview 文本在代码中设置粗体效果
- android textview 水平滚动
- android 设置textview中划线效果