Android 使用 ellipsize 实现文字横向移动效果(跑马灯效果)

实现的效果图如下

ellipsize 可以设置跑马灯效果 具体代码设置如下

 <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:layout_marginTop="100dp"
            android:focusableInTouchMode="true"
            android:singleLine="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:text="君不见,黄河之水天上来,奔流到海不复回。君不见,高堂明镜悲白发,朝如青丝暮成雪。人生得意须尽欢,莫使金樽空对月。天生我材必有用,千金散尽还复来。烹羊宰牛且为乐,会须一饮三百杯。岑夫子,丹丘生,将进酒,杯莫停"
            android:textColor="@android:color/holo_red_dark">

        <requestFocus />
    </TextView>

 android:ellipsize="marquee" //设置为跑马灯效果

android:marqueeRepeatLimit="marquee_forever" //设置为重复走动

android:focusable="true" //获取焦点

android:singleLine="true" //单行文字 

android:focusableInTouchMode="true" //获取focus

猜你喜欢

转载自blog.csdn.net/qq_33210042/article/details/100918768