您的位置:首页 > 移动开发 > Android开发

android TextView跑马灯 让字体滚动起来

2016-07-28 14:17 357 查看
一个界面中,只能有一个textView获得焦点,暂时只能让一个textView的文字滚动起来

第一步自定义控件

public class Marquee extends TextView {
public Marquee(Context con) {
super(con);
}

public Marquee(Context context, AttributeSet attrs) {
super(context, attrs);
}
public Marquee(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean isFocused() {
return true;
}

}


第二步 xml布局中设置

<com.zhongguo.paomadeng.Marquee
android:id="@+id/item1_title_message"
android:layout_below="@+id/AMTV1"
android:layout_width="160dip"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:layout_marginLeft="20dip"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:text="新华社北京7月27日电(记者李宣良、李清华)八一建军节到来之际,中共中央总书记、国家主席、中央军委主席习近平27日上午视察陆军机关,代表党中央和中央军委,对陆军第一次党代表大会的召开表示热烈的祝贺,向人民解放军全体指战员、武警部队全体官兵、民兵预备役人员致以节日的问候。"/>


说明:

android:singleLine="true"       //是否单行显示文本
android:ellipsize="marquee"     //文本超过控件长度,如何处理文本内容,此处为滚动动画显示
android:focusable="true"        //是否获得焦点
android:focusableInTouchMode="true"    //是否在触摸模式下获得焦点
android:marqueeRepeatLimit="marquee_forever"//重复滚动的次数


原生控件 加上下面的属性就可以

android:focusable="true"
android:singleLine="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Marquee 跑马灯