温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

android跑马灯出现重复跳动以及不滚动怎么解决

发布时间:2021-09-15 20:11:07 来源:亿速云 阅读:170 作者: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