android中怎么利用TextView實現跑馬燈效果-創新互聯

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

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

一、要點

設置四個屬性

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

注意:singleLine屬性 不能換成 maxlLines

二、復雜布局

在復雜的布局中可能不會實現跑馬燈效果。例如如下布局中,就只有第一個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="人生是一場無休、無歇、無情的戰斗,凡是要做個夠得上稱為人的人,都得時時向無形的敵人作戰。" />
 <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="人生是一場無休、無歇、無情的戰斗,凡是要做個夠得上稱為人的人,都得時時向無形的敵人作戰。" />


</RelativeLayout>

這時候就需要自定義View,實現跑馬燈效果

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


</RelativeLayout>

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

本文標題:android中怎么利用TextView實現跑馬燈效果-創新互聯
文章鏈接:http://m.kartarina.com/article34/egppe.html

成都網站建設公司_創新互聯,為您提供面包屑導航、App開發、企業網站制作、動態網站、App設計、品牌網站建設

廣告

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

外貿網站制作
主站蜘蛛池模板: 日韩激情无码免费毛片| 亚洲色无码国产精品网站可下载| 国产一区二区三区无码免费| 无码av中文一二三区| 久久亚洲精品无码| 国产成人亚洲精品无码AV大片| 亚洲中文字幕无码永久在线| 国产福利无码一区在线| 精品无码人妻一区二区免费蜜桃 | 狠狠躁狠狠爱免费视频无码 | 免费无码又爽又刺激高潮软件| 亚洲AV永久青草无码精品| 亚洲Av无码国产情品久久| 成人无码区免费A片视频WWW| 亚洲国产综合无码一区| 无码视频在线播放一二三区| 无码精品A∨在线观看无广告| 97免费人妻无码视频| 人妻丰满熟妇av无码区不卡| 国产亚洲3p无码一区二区| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 免费无遮挡无码视频在线观看 | 99久久国产热无码精品免费| 亚洲AV无码乱码国产麻豆| 亚洲av永久无码制服河南实里| 亚洲熟妇少妇任你躁在线观看无码 | 亚洲AV日韩AV无码污污网站 | 久久亚洲精品无码aⅴ大香| 亚洲综合av永久无码精品一区二区| 色欲aⅴ亚洲情无码AV| 好了av第四综合无码久久| 在线观看无码AV网址| 精品久久久久久无码不卡| 久久亚洲精品成人av无码网站| 午夜无码伦费影视在线观看| 十八禁无码免费网站| 最新无码人妻在线不卡| 无码熟妇人妻AV在线影院| 国产AV无码专区亚洲AV蜜芽| 亚洲精品一级无码中文字幕| 十八禁视频在线观看免费无码无遮挡骂过|