日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android文字实现跑马灯效果——两种方法实现

發布時間:2024/3/13 Android 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android文字实现跑马灯效果——两种方法实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第一種方法,設置textView的屬性

<com.example.glide.MarqueeViewandroid:id="@+id/marqueeView"android:layout_width="match_parent"android:layout_height="wrap_content"android:ellipsize="marquee"android:focusable="true"android:focusableInTouchMode="true"android:marqueeRepeatLimit="marquee_forever"android:scrollHorizontally="true"android:singleLine="true"android:text="心中有陽光,腳底有力量!心中有陽光,腳底有力量!心中有陽光,腳底有力量!"android:textSize="40sp"android:textColor="#ff0000"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toBottomOf="@+id/banner" />

上面屬性,這幾個屬性的意義

? ? ? ? android:ellipsize="marquee"? ?//跑馬燈效果
? ? ? ? android:focusable="true"? ? ? ? //焦點獲取第一步
? ? ? ? android:focusableInTouchMode="true"? ? //焦點獲取第二步
? ? ? ? android:marqueeRepeatLimit="marquee_forever"? ?//循環顯示

此控件是繼承TextView控件,故繼承類

public class MarqueeView extends TextView {public MarqueeView(Context context) {super(context);}public MarqueeView(Context context, @Nullable AttributeSet attrs) {super(context, attrs);}public MarqueeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);}@Overridepublic boolean isFocused() {return true;} }

通過上面兩步,就可以實現跑馬燈的效果

第二種方式 采用第三方開源庫

GitHub地址

https://github.com/sunfusheng/MarqueeView

1、gradle

implementation 'com.sunfusheng:MarqueeView:1.4.1'

2、配置xml文件

<com.sunfusheng.marqueeview.MarqueeViewandroid:id="@+id/marqueeView"android:layout_width="match_parent"android:layout_height="30dp"app:mvAnimDuration="1000"app:mvDirection="bottom_to_top"app:mvInterval="3000"app:mvTextColor="@color/white"app:mvTextSize="14sp"app:mvSingleLine="true"app:mvFont="@font/huawenxinwei"/>

詳細屬性參考GitHub

3、顯示數據

String message = "心中有陽光,腳底有力量!心中有陽光,腳底有力量!心中有陽光,腳底有力量!"; marqueeView.startWithText(message);// 在代碼里設置自己的動畫 marqueeView.startWithText(message, R.anim.anim_bottom_in, R.anim.anim_top_out);

更多功能參考GitHub

總結

以上是生活随笔為你收集整理的Android文字实现跑马灯效果——两种方法实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。