这篇文章主要介绍了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跑马灯出现重复跳动以及不滚动问题的解决方法
基础教程推荐
- android studio按钮监听的5种方法实例详解 2023-01-12
- Android多返回栈技术 2023-04-15
- Android中的webview监听每次URL变化实例 2023-01-23
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- Flutter手势密码的实现示例(附demo) 2023-04-11
- iOS开发教程之XLForm的基本使用方法 2023-05-01
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
