欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android基于TextView實現(xiàn)跑馬燈效果

 更新時間:2017年03月11日 10:12:14   作者:慧琳女神的小粉絲  
這篇文章主要為大家詳細(xì)介紹了Android基于TextView實現(xiàn)跑馬燈效果的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

當(dāng)Layout中只有一個TextView需要實現(xiàn)跑馬燈效果時,操作如下。
在Layout的TextView配置文件中增加

        android:ellipsize="marquee"

        android:focusable="true"

        android:focusableInTouchMode="true"

        android:singleLine="true"

以上四條屬性,即可實現(xiàn)跑馬燈效果。

當(dāng)有多個TextView想實現(xiàn)跑馬燈效果時,實現(xiàn)起來稍微復(fù)雜一些。
首先新建一個類,繼承自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;
  }
}

重寫函數(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" />

此時兩個TextView都可呈現(xiàn)跑馬燈效果。

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

相關(guān)文章

最新評論