最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android TextView實(shí)現(xiàn)跑馬燈效果

 更新時(shí)間:2017年06月30日 14:07:15   作者:段合江  
這篇文章主要為大家詳細(xì)介紹了android TextView實(shí)現(xiàn)跑馬燈效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了android TextView跑馬燈效果的具體代碼,供大家參考,具體內(nèi)容如下

一、要點(diǎn)

設(shè)置四個(gè)屬性

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

直接在xml中使用

<TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:singleLine="true"
  android:ellipsize="marquee"
  android:focusable="true"
  android:focusableInTouchMode="true"
  android:text="人生是一場(chǎng)無休、無歇、無情的戰(zhàn)斗,凡是要做個(gè)夠得上稱為人的人,都得時(shí)時(shí)向無形的敵人作戰(zhàn)。" />


注意:singleLine屬性 不能換成 maxlLines 

二、復(fù)雜布局

在復(fù)雜的布局中可能不會(huì)實(shí)現(xiàn)跑馬燈效果。例如如下布局中,就只有第一個(gè)TextView會(huì)有跑馬燈效果

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:id="@+id/tv1"
  android:singleLine="true"
  android:ellipsize="marquee"
  android:focusable="true"
  android:focusableInTouchMode="true"
  android:text="人生是一場(chǎng)無休、無歇、無情的戰(zhàn)斗,凡是要做個(gè)夠得上稱為人的人,都得時(shí)時(shí)向無形的敵人作戰(zhàn)。" />
 <TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_below="@+id/tv1"
  android:layout_marginTop="10dp"
  android:singleLine="true"
  android:ellipsize="marquee"
  android:focusable="true"
  android:focusableInTouchMode="true"
  android:text="人生是一場(chǎng)無休、無歇、無情的戰(zhàn)斗,凡是要做個(gè)夠得上稱為人的人,都得時(shí)時(shí)向無形的敵人作戰(zhàn)。" />


</RelativeLayout>

這時(shí)候就需要自定義View,實(shí)現(xiàn)跑馬燈效果

自定義MarQueeTextView extents TextView  重寫isFocused()方法,返回true

public class MarqueeText extends TextView {
 public MarqueeText(Context context) {
  super(context);
 }

 public MarqueeText(Context context, @Nullable AttributeSet attrs) {
  super(context, attrs);
 }

 public MarqueeText(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
 }

 @Override
 public boolean isFocused() {
  return true;
 }
}

布局中使用

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <com.example.dhj.marqueedemo.View.MarqueeText
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:id="@+id/tv1"
  android:singleLine="true"
  android:ellipsize="marquee"
  android:focusable="true"
  android:focusableInTouchMode="true"
  android:text="人生是一場(chǎng)無休、無歇、無情的戰(zhàn)斗,凡是要做個(gè)夠得上稱為人的人,都得時(shí)時(shí)向無形的敵人作戰(zhàn)。" />
 <com.example.dhj.marqueedemo.View.MarqueeText
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_below="@+id/tv1"
  android:layout_marginTop="10dp"
  android:singleLine="true"
  android:ellipsize="marquee"
  android:focusable="true"
  android:focusableInTouchMode="true"
  android:text="人生是一場(chǎng)無休、無歇、無情的戰(zhàn)斗,凡是要做個(gè)夠得上稱為人的人,都得時(shí)時(shí)向無形的敵人作戰(zhàn)。" />


</RelativeLayout>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

大英县| 砚山县| 深水埗区| 阿克陶县| 永吉县| 泗洪县| 江源县| 海原县| 威海市| 余江县| 藁城市| 雷山县| 大石桥市| 二手房| 贺州市| 洪江市| 隆化县| 常德市| 唐海县| 进贤县| 温泉县| 古蔺县| 新绛县| 广州市| 格尔木市| 海宁市| 中宁县| 林西县| 桦南县| 周口市| 铁岭市| 尤溪县| 株洲县| 海兴县| 彩票| 宁武县| 河间市| 丹东市| 扎鲁特旗| 赤峰市| 永清县|