欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

android中怎么利用TextView實現(xiàn)跑馬燈效果-創(chuàng)新互聯(lián)

這篇文章給大家介紹android中怎么利用TextView實現(xiàn)跑馬燈效果,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

成都創(chuàng)新互聯(lián)公司是創(chuàng)新、創(chuàng)意、研發(fā)型一體的綜合型網(wǎng)站建設(shè)公司,自成立以來公司不斷探索創(chuàng)新,始終堅持為客戶提供滿意周到的服務,在本地打下了良好的口碑,在過去的十年時間我們累計服務了上千家以及全國政企客戶,如社區(qū)文化墻等企業(yè)單位,完善的項目管理流程,嚴格把控項目進度與質(zhì)量監(jiān)控加上過硬的技術(shù)實力獲得客戶的一致表揚。

一、要點

設(shè)置四個屬性

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="人生是一場無休、無歇、無情的戰(zhàn)斗,凡是要做個夠得上稱為人的人,都得時時向無形的敵人作戰(zhàn)。" />

注意:singleLine屬性 不能換成 maxlLines

二、復雜布局

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

<?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="人生是一場無休、無歇、無情的戰(zhàn)斗,凡是要做個夠得上稱為人的人,都得時時向無形的敵人作戰(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="人生是一場無休、無歇、無情的戰(zhàn)斗,凡是要做個夠得上稱為人的人,都得時時向無形的敵人作戰(zhàn)。" />


</RelativeLayout>

這時候就需要自定義View,實現(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="人生是一場無休、無歇、無情的戰(zhàn)斗,凡是要做個夠得上稱為人的人,都得時時向無形的敵人作戰(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="人生是一場無休、無歇、無情的戰(zhàn)斗,凡是要做個夠得上稱為人的人,都得時時向無形的敵人作戰(zhàn)。" />


</RelativeLayout>

關(guān)于android中怎么利用TextView實現(xiàn)跑馬燈效果就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

本文標題:android中怎么利用TextView實現(xiàn)跑馬燈效果-創(chuàng)新互聯(lián)
文章鏈接:http://chinadenli.net/article34/egppe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導航App開發(fā)企業(yè)網(wǎng)站制作動態(tài)網(wǎng)站App設(shè)計品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作