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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android 走马灯效果

發布時間:2024/4/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 走马灯效果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最進其實自己也沒什么想寫的內容,不過自己覺得還是需要每天寫點東西,好的習慣還是要保持的。所以今天講講textview的文字顯示走馬燈的效果,這個實在太簡單了。

項目開發中有些時候TextView的文本內容太長了顯示不全,這個時候需要讓它實現像網頁上面的跑馬燈效果,網上很多文章都是自定義控件繼承自TextView來實現的,自己在實踐中發現不用自定義控件也可以實現跑馬燈的效果,因為Android原生的TextView已經支持跑馬燈的效果了。

關鍵之處在于設置TextView的四個屬性值:

android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"


尤其是下面兩個屬性:

android:focusable="true"
android:focusableInTouchMode="true"

只有當它獲取到焦點的時候才會滾動。

完整布局如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
??? xmlns:tools="http://schemas.android.com/tools"
??? android:layout_width="match_parent"
??? android:layout_height="match_parent"
??? tools:context=".MainActivity"
??? android:orientation="vertical">

??? <TextView
??????? android:id="@+id/tv"
??????? android:layout_width="wrap_content"
??????? android:layout_height="wrap_content"
??????? android:ellipsize="marquee"
??????? android:focusable="true"
??????? android:focusableInTouchMode="true"
??????? android:marqueeRepeatLimit="marquee_forever"
??????? android:singleLine="true"
??????? android:text="@string/txt_title"
??????? android:textSize="15sp"/>

??? <Button
??????? android:layout_width="wrap_content"
??????? android:layout_height="wrap_content"
??????? android:text="@string/confirm"
??????? android:textSize="15sp"/>

</LinearLayout>


其實主要的屬性是android:ellipsize="marquee"和android:marqueeRepeatLimit="marquee_forever"?,這兩個一個是設置文字的走馬德燈效果,一個是設置文字一直移動,當然文字必須足夠長,才會有效果。


設置textView走馬燈效果就講完了。


就這么簡單。


















總結

以上是生活随笔為你收集整理的android 走马灯效果的全部內容,希望文章能夠幫你解決所遇到的問題。

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