溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

android跑馬燈出現重復跳動以及不滾動怎么解決

發布時間:2021-09-15 20:11:07 來源:億速云 閱讀:291 作者:chen 欄目:開發技術

本篇內容主要講解“android跑馬燈出現重復跳動以及不滾動怎么解決”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“android跑馬燈出現重復跳動以及不滾動怎么解決”吧!

原因:頁面有View被重新繪制了、焦點被搶占

例如:

1、TextView 的width被設置為wrap_content,setText()時內容改變會導致View重新繪制;
2、頁面中動態生成View同樣會影響跑馬燈效果;

解決辦法:

1.盡可能的將頁面的View的寬和高設置為固定值,盡量不要動態去修改

2.自定義TextView 重寫isFocused()函數,讓他放回true也就是一直獲取了,焦點效果自然也就出來了,如果這都不能解決那肯就不是焦點問題了。

public class MarqueTextView extends TextView {

    public MarqueTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public MarqueTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MarqueTextView(Context context) {
        super(context);
    }

    @Override

    public boolean isFocused() {
        return true;
    }
    @Override
    protected void onFocusChanged(boolean focused, int direction,
                                  Rect previouslyFocusedRect) {
        if(focused){
            super.onFocusChanged(focused,direction,previouslyFocusedRect);
        }
    }

    @Override
    public void onWindowFocusChanged(boolean focused)
    {
        if (focused)
        {
            super.onWindowFocusChanged(focused);
        }
    }
}

小編之前還看到一個關于android跑馬燈重復抖動的解決方法,也分享給大家,謝謝原作者的分享

先貼一下TextView跑馬燈的實現代碼

<TextView
       android:id="@+id/tv_blueToothDatas"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:textColor="@color/yellow_f38131"
       android:singleLine="true"
       android:ellipsize="marquee"
       android:focusable="true"
       android:focusableInTouchMode="true"
       android:marqueeRepeatLimit="marquee_forever"
/>

出現的問題,在界面上,有一個用viewPager實現的廣告輪播功能,發現每次切換廣告的時候,跑馬燈會跳動,并且從頭顯示,以為是viewPager與跑馬燈沖突,后來在網上搜了一下,android 6.0有時候會出現這個問題,解決的方法,在跑馬燈控件外層,再嵌套一個布局控件

<LinearLayout android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1"
         android:orientation="horizontal"
         android:layout_marginLeft="5dp"
         android:layout_marginRight="5dp">
       <TextView
         android:id="@+id/tv_blueToothDatas"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         tools:text="11111111111111111111111111111111111111111111111"
         android:textColor="@color/yellow_f38131"
         android:singleLine="true"
         android:ellipsize="marquee"
         android:focusable="true"
         android:focusableInTouchMode="true"
         android:marqueeRepeatLimit="marquee_forever"
     />
</LinearLayout>

到此,相信大家對“android跑馬燈出現重復跳動以及不滾動怎么解決”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女