TextView文字横向自动滚动(跑马灯)
来源:互联网 发布:linux assert 头文件 编辑:程序博客网 时间:2024/04/29 14:46
publicclass AlwaysMarqueeTextView extends TextView {
publicAlwaysMarqueeTextView(Contextcontext) {
super(context);
}
publicAlwaysMarqueeTextView(Contextcontext,AttributeSet attrs) {
super(context,attrs);
}
publicAlwaysMarqueeTextView(Contextcontext,AttributeSet attrs,int defStyle) {
super(context,attrs,defStyle);
}
@Override
publicboolean isFocused() {
returntrue;
}
在布局XML文件中加入这么一个AlwaysMarqueeTextView,这个加入方法也是刚刚学的。
android:id=“@+id/AMTV1″
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:lines=“1″
android:focusable=“true”
android:focusableInTouchMode=“true”
android:scrollHorizontally=“true”
android:marqueeRepeatLimit=“marquee_forever”
android:ellipsize=“marquee”
android:background=“@android:color/transparent”
/>
ellipsize属性
设置当文字过长时,该控件该如何显示。有如下值设置:”start”—–省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动)
marqueeRepeatLimit属性
在ellipsize指定marquee的情况下,设置重复滚动的次数,当设置为marquee_forever时表示无限次。
组合View的问题:
xmlns:android =“http://schemas.android.com/apk/res/android”
android:orientation =“vertical”
android:gravity =“center_vertical”
android:background =“@drawable/f_background”
android:layout_width =“fill_parent”
android:focusable =“true”
android:layout_height =“50px”>
< TextView
android:id =“@+id/info_text”
android:focusable =“true”
android:layout_width =“fill_parent”
android:layout_height =“wrap_content”
android:text =“test marquee .. “
android:textColor =“@color/black”
android:singleLine =“true”
android:ellipsize =“marquee”
android:marqueeRepeatLimit =“3″
android:textSize =“18sp”
/>
< TextView
android:id =“@+id/date_text”
android:layout_width =“fill_parent”
android:layout_height =“wrap_content”
android:layout_gravity =“bottom”
android:textColor =“@color/gray”
android:text =“2010/05/28″
android:textSize =“12sp”
/>
</ LinearLayout >
上面示例中2个TextView组合为一个View,由于设置了LinearLayout为focusable而TextView就没法取得焦点了,这样 这个TextView的跑马灯效果就显示不出来,就算你也设置TextView的android:focusable=
"true"
也是 没用的. 这个时候就要使用addStatesFromChildren 这个属性了,在LinearLayout中设置这个属性,然后设置TextView的focusable=
"true"
就可以了.关于 addStatesFromChildren的说明:
Sets whether
this
ViewGroup's drawable states
also include its children's drawable states.
- TextView文字横向自动滚动(跑马灯)
- Android TextView文字横向自动滚动(跑马灯)
- Android TextView文字横向自动滚动(跑马灯)
- Android TextView文字横向自动滚动(跑马灯)
- Android TextView文字横向自动滚动(跑马灯)
- Android TextView文字横向自动滚动(跑马灯)
- Android TextView文字横向自动滚动(跑马灯)
- Android TextView文字横向自动滚动(跑马灯)
- Android:TextView文字横向自动滚动(跑马灯)
- Android TextView文字横向自动滚动(跑马灯)
- adnroid textview设置文字横向自动滚动(跑马灯效果)
- TextView文字横向滚动(跑马灯效果)
- TextView文字横向自动滚动
- TextView跑马灯效果,也就是,自动滚动文字的效果。
- TextView 自动滚动(跑马灯)
- TextView 文字滚动 跑马灯效果
- Android TextView 横向滚动(跑马灯效果)
- Android 小样之TextView横向滚动(跑马灯效果)
- android 程序安装以后不要显示图标
- droid 指定Toast信息显示的位置并使用Toast显示其他View
- 简单android音乐播放器上 android学习(二)
- 利用命令行从github下载框架及包含的子工程
- iOS iPhone官方参考资料明细
- TextView文字横向自动滚动(跑马灯)
- DataTable筛选,取前N条数据,获取指定列数据
- 记者为什么也要学点数学?
- failed to pull a selection
- Ubuntu上进行网络抓包
- 由下至上弹出并位于屏幕底部的提示框
- Reservoir Sampling - Sampling from a stream of elements(蓄水池算法,从流数据中抽样)
- android中常用的弹出提示框
- Linux 2.6驱动开发环境搭建