阅读 259

android跑马灯出现重复跳动以及不滚动问题的解决方法

这篇文章主要介绍了android跑马灯出现重复跳动以及不滚动问题的解决方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

android跑马灯出现重复跳动、不滚动问题,本文给出解决方案,供大家参考。

原因:页面有View被重新绘制了、焦点被抢占

例如:

1、TextView 的width被设置为wrap_content,setText()时内容改变会导致View重新绘制;
2、页面中动态生成View同样会影响跑马灯效果;

解决办法:

1.尽可能的将页面的View的宽和高设置为固定值,尽量不要动态去修改

2.自定义TextView 重写isFocused()函数,让他放回true也就是一直获取了,焦点效果自然也就出来了,如果这都不能解决那肯就不是焦点问题了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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跑马灯的实现代码

1
2
3
4
5
6
7
8
9
10
11
<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有时候会出现这个问题,解决的方法,在跑马灯控件外层,再嵌套一个布局控件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<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>

以上就是本文的全部内容,希望对大家的学习有所帮助

原文链接:https://blog.csdn.net/SmilingGirl_/article/details/77978672

服务器评测 http://www.cncsto.com/ 

服务器测评 http://www.cncsto.com/ 

站长资源 https://www.cscnn.com/ 

小鱼创业 https://www.237fa.com/ 


文章分类
后端
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐