亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

android跑馬燈出現(xiàn)重復(fù)跳動(dòng)以及不滾動(dòng)問題的解決方法

 更新時(shí)間:2021年09月15日 17:18:21   作者:SmilingGirl_  
這篇文章主要介紹了android跑馬燈出現(xiàn)重復(fù)跳動(dòng)以及不滾動(dòng)問題的解決方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

android跑馬燈出現(xiàn)重復(fù)跳動(dòng)、不滾動(dòng)問題,本文給出解決方案,供大家參考。

原因:頁面有View被重新繪制了、焦點(diǎn)被搶占

例如:

1、TextView 的width被設(shè)置為wrap_content,setText()時(shí)內(nèi)容改變會(huì)導(dǎo)致View重新繪制;
2、頁面中動(dòng)態(tài)生成View同樣會(huì)影響跑馬燈效果;

解決辦法:

1.盡可能的將頁面的View的寬和高設(shè)置為固定值,盡量不要?jiǎng)討B(tài)去修改

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

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);
        }
    }
}

小編之前還看到一個(gè)關(guān)于android跑馬燈重復(fù)抖動(dòng)的解決方法,也分享給大家,謝謝原作者的分享

先貼一下TextView跑馬燈的實(shí)現(xiàn)代碼

<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"
/>

出現(xiàn)的問題,在界面上,有一個(gè)用viewPager實(shí)現(xiàn)的廣告輪播功能,發(fā)現(xiàn)每次切換廣告的時(shí)候,跑馬燈會(huì)跳動(dòng),并且從頭顯示,以為是viewPager與跑馬燈沖突,后來在網(wǎng)上搜了一下,android 6.0有時(shí)候會(huì)出現(xiàn)這個(gè)問題,解決的方法,在跑馬燈控件外層,再嵌套一個(gè)布局控件

<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>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論