Android基于TextView實(shí)現(xiàn)跑馬燈效果
本文實(shí)例為大家分享了Android TextView實(shí)現(xiàn)跑馬燈效果的具體代碼,供大家參考,具體內(nèi)容如下
當(dāng)Layout中只有一個(gè)TextView需要實(shí)現(xiàn)跑馬燈效果時(shí),操作如下。
在Layout的TextView配置文件中增加
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
以上四條屬性,即可實(shí)現(xiàn)跑馬燈效果。
當(dāng)有多個(gè)TextView想實(shí)現(xiàn)跑馬燈效果時(shí),實(shí)現(xiàn)起來(lái)稍微復(fù)雜一些。
首先新建一個(gè)類,繼承自TextView。
package com.example.project1;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewDebug.ExportedProperty;
import android.widget.TextView;
public class MyTextView extends TextView{
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MyTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public boolean isFocused() {
// TODO Auto-generatd method stub
return true;
}
}
重寫(xiě)函數(shù) isFocused(),使其始終return true。
將Layout文件中的TextView修改為com.example.project1.MyTextView,如下。
<com.example.project1.MyTextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:text="@string/longText" />
<com.example.project1.MyTextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:text="@string/longText" />
此時(shí)兩個(gè)TextView都可呈現(xiàn)跑馬燈效果。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- TextView實(shí)現(xiàn)跑馬燈效果 就這么簡(jiǎn)單!
- android TextView實(shí)現(xiàn)跑馬燈效果
- Android自定義TextView跑馬燈效果
- Android中使用TextView實(shí)現(xiàn)文字跑馬燈效果
- Android使用TextView跑馬燈效果
- Android 中TextView中跑馬燈效果的實(shí)現(xiàn)方法
- Android TextView實(shí)現(xiàn)跑馬燈效果的方法
- Android TextView跑馬燈效果實(shí)現(xiàn)方法
- Android用過(guò)TextView實(shí)現(xiàn)跑馬燈效果的示例
相關(guān)文章
android實(shí)現(xiàn)密碼框右側(cè)顯示小眼睛
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)密碼框右側(cè)顯示小眼睛,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09
ScrollView與SeekBar綁定實(shí)現(xiàn)滑動(dòng)時(shí)出現(xiàn)小滑塊效果
這篇文章主要為大家詳細(xì)介紹了ScrollView與SeekBar綁定實(shí)現(xiàn)滑動(dòng)時(shí)出現(xiàn)小滑塊效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
Android 彩色Toast的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 彩色Toast的實(shí)現(xiàn)代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-10-10
android使用RxJava實(shí)現(xiàn)預(yù)加載
這篇文章主要為大家詳細(xì)介紹了android使用RxJava實(shí)現(xiàn)預(yù)加載的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01
淺析Flutter AbsorbPointer 與 IgnorePointer的區(qū)別
Flutter是Google一個(gè)新的用于構(gòu)建跨平臺(tái)的手機(jī)App的SDK。這篇文章主要介紹了Flutter AbsorbPointer 與 IgnorePointer的區(qū)別,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04
在ubuntu下編譯ijkplayer-android的方法
下面小編就為大家分享一篇在ubuntu下編譯ijkplayer-android的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01

