国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android基于TextView實現跑馬燈效果

2019-10-23 18:35:04
字體:
來源:轉載
供稿:網友

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

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

        android:ellipsize="marquee"

        android:focusable="true"

        android:focusableInTouchMode="true"

        android:singleLine="true"

以上四條屬性,即可實現跑馬燈效果。

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

重寫函數 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都可呈現跑馬燈效果。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 英吉沙县| 伊春市| 元阳县| 隆安县| 金坛市| 石狮市| 安龙县| 天津市| 钟祥市| 曲靖市| 三门县| 丹江口市| 文山县| 济源市| 新乡市| 肥西县| 富蕴县| 广南县| 安徽省| 从化市| 全椒县| 隆尧县| 沈丘县| 石家庄市| 仙桃市| 丹江口市| 师宗县| 腾冲县| 红河县| 梁山县| 凉城县| 阿鲁科尔沁旗| 深泽县| 双流县| 淮滨县| 连山| 赣州市| 崇信县| 塔河县| 重庆市| 迁安市|