TextView實(shí)現(xiàn)跑馬燈效果 就這么簡單!
一、方法
這里我們用兩種方法來實(shí)現(xiàn)跑馬燈效果,雖然實(shí)質(zhì)上是一種
實(shí)質(zhì)就是:
1、TextView調(diào)出跑馬燈效果
2、TextView獲取焦點(diǎn)
第一種:
1、TextView調(diào)出跑馬燈效果
android:ellipsize="marquee"
2、TextView獲取焦點(diǎn)
android:focusable="true"
android:focusableInTouchMode="true"
說明:
這種方法如果界面上別的控件獲取焦點(diǎn)的時候就會停止這個跑馬燈效果
第二種:
1、TextView調(diào)出跑馬燈效果
android:ellipsize="marquee"
2、TextView獲取焦點(diǎn)
public class MyTextView extends TextView{
public boolean isFocused() {
return true;
}
}
我們的TextView用的就是fry.MyTextView
說明:
就算別的程序獲取焦點(diǎn),這個跑馬燈效果也不會停止。
二、代碼實(shí)例
效果圖

三、代碼
fry.MyTextView
package com.example.textviewdemo;
import android.content.Context;
import android.util.AttributeSet;
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() {
return true;
}
}
/textViewDemo1/res/layout/activity04.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/tv_runHorseLamp" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:text="這是一段很長的威武霸氣的滾動的實(shí)現(xiàn)跑馬燈效果的一段逼格很高的很有含義和涵養(yǎng)的文字" /> <!--ellipsize是小數(shù)點(diǎn)的意思 marquee 這句話是添加滾動效果--> <!-- 獲取焦點(diǎn)之后才能滾動 --> <fry.MyTextView android:id="@+id/tv_runHorseLamp1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="marquee" android:singleLine="true" android:text="這是一段很長的威武霸氣的滾動的實(shí)現(xiàn)跑馬燈效果的一段逼格很高的很有含義和涵養(yǎng)的文字" /> <EditText android:id="@+id/et_1" android:layout_width="match_parent" android:layout_height="wrap_content" > </EditText> </LinearLayout>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 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 TextView跑馬燈效果實(shí)現(xiàn)方法
- Android用過TextView實(shí)現(xiàn)跑馬燈效果的示例
相關(guān)文章
android實(shí)現(xiàn)Splash閃屏效果示例
這篇文章主要介紹了android實(shí)現(xiàn)Splash閃屏效果的方法,涉及Android中postDelayed方法及AndroidManifest.xml權(quán)限控制的相關(guān)使用技巧,需要的朋友可以參考下2016-08-08
講解Android中的Widget及AppWidget小工具的創(chuàng)建實(shí)例
這篇文章主要介紹了講解Android中的Widget及Widget的創(chuàng)建實(shí)例,文中的例子展示了通過RemoteView來溝通AppWidgetProvider與AppWidgetHostView的方法,需要的朋友可以參考下2016-03-03
android 選項(xiàng)卡(TabHost)如何放置在屏幕的底部
如何將TAB放置在屏幕的底端,有很多的新手都想實(shí)現(xiàn)這種效果,本文搜集整理了一些,感興趣的朋友可以參考下哦2013-01-01
Android GuideView實(shí)現(xiàn)首次登陸引導(dǎo)
這篇文章主要為大家詳細(xì)介紹了Android GuideView實(shí)現(xiàn)首次登陸引導(dǎo),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-03-03
android里面屏蔽home鍵/禁止Home鍵或者隨你DIY
可以先禁止Home鍵,再在onKeyDown里處理按鍵值,點(diǎn)然后在擊Home鍵的時候就把程序關(guān)閉,或者隨你DIY等等,感覺你可以隨心所欲吧,再接再厲,希望本文可以幫助到你2013-01-01
Android IPC進(jìn)程間通信詳解最新AndroidStudio的AIDL操作)
這篇文章主要介紹了Android IPC進(jìn)程間通信的相關(guān)資料,需要的朋友可以參考下2016-09-09
Android基于OpenGL的GLSurfaceView創(chuàng)建一個Activity實(shí)現(xiàn)方法
這篇文章主要介紹了Android基于OpenGL的GLSurfaceView創(chuàng)建一個Activity實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了Android中OpenGL圖形操作類GLSurfaceView的功能、用法及相關(guān)使用技巧,需要的朋友可以參考下2016-10-10

