中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Android自定義TextView實(shí)現(xiàn)跑馬燈功能

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用

首先我們要實(shí)現(xiàn)走馬燈這樣一個(gè)效果,通常來(lái)說(shuō)都是在TextView這個(gè)控件中來(lái)實(shí)現(xiàn)的,而且其中的文字一定是單行顯示,如果多行顯示,那走馬燈效 果也就失去了存在的意義。談到TextView的跑馬燈,我們首先應(yīng)該想到android:ellipsize="marquee"(start、end 屬性表示前或者后省略),而如果要在view中實(shí)現(xiàn)跑馬燈功能,就需要TextView改為Button,開(kāi)啟觸控焦點(diǎn)在開(kāi)啟狀態(tài) android:focusableInTouchMode="true",否則是不會(huì)看到跑馬燈效果的。

未用自定義TextView實(shí)現(xiàn)跑馬燈代碼:

    <Button   
            android:focusableInTouchMode="true"  
            android:singleLine="true"  
            android:ellipsize="marquee"  
            android:text="未使用自定義TextView的跑馬燈效果"  
            android:textSize="18sp"  
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content"  
            />  

下面使用自定義TextView實(shí)現(xiàn)跑馬燈:

先編寫自定義TextView

    package com.zebra.mobilesafe.ui;  
      
    import android.content.Context;  
    import android.util.AttributeSet;  
    import android.view.ViewDebug.ExportedProperty;  
    import android.widget.TextView;  
      
    /** 
     * 自定義一個(gè)TextView,是他天生就有焦點(diǎn) 
     * @author Administrator 
     * 
     */  
    public class FocusTextView extends TextView {  
      
        public FocusTextView(Context context, AttributeSet attrs, int defStyle) {  
            super(context, attrs, defStyle);  
            // TODO Auto-generated constructor stub  
        }  
      
        public FocusTextView(Context context, AttributeSet attrs) {  
            super(context, attrs);  
            // TODO Auto-generated constructor stub  
        }  
      
        public FocusTextView(Context context) {  
            super(context);  
            // TODO Auto-generated constructor stub  
        }  
      
        /** 
         * 欺騙Android系統(tǒng),讓當(dāng)前沒(méi)有焦點(diǎn)的判斷為true,實(shí)現(xiàn)button效果 
         */  
        @Override  
        @ExportedProperty(category = "focus")  
        public boolean isFocused() {  
            // TODO Auto-generated method stub  
            return true;  
        }  
    }  

然后在android的xml文件中,引用自定義實(shí)現(xiàn),路徑要是類的絕對(duì)路徑
    <com.zebra.mobilesafe.ui.FocusTextView  
        android:singleLine="true"  
        android:ellipsize="marquee"  
        android:text="使用自定義TextView的跑馬燈效果"  
        android:textSize="18sp"  
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content"  
        />  

這樣就可以在TextView中實(shí)現(xiàn)跑馬燈效果了。

標(biāo)簽: 代碼

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:HttpClient4 設(shè)置代理

下一篇:使用Javascript設(shè)置,獲取和刪除cookie