android跑馬燈出現(xiàn)重復(fù)跳動(dòng)以及不滾動(dòng)問題的解決方法
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í)有所幫助,也希望大家多多支持腳本之家。
- Android 中TextView中跑馬燈效果的實(shí)現(xiàn)方法
- Android TextView實(shí)現(xiàn)跑馬燈效果的方法
- Android實(shí)現(xiàn)跑馬燈效果的方法
- Android自定義View實(shí)現(xiàn)豎直跑馬燈效果案例解析
- Android實(shí)現(xiàn)圖文垂直跑馬燈效果
- Android自定義textview實(shí)現(xiàn)豎直滾動(dòng)跑馬燈效果
- Android中使用TextView實(shí)現(xiàn)文字跑馬燈效果
- Android基于TextView不獲取焦點(diǎn)實(shí)現(xiàn)跑馬燈效果
- Android跑馬燈MarqueeView源碼解析
- android自定義View實(shí)現(xiàn)跑馬燈效果
相關(guān)文章
Android傳感器SensorEventListener之加速度傳感器
今天小編就為大家分享一篇關(guān)于Android傳感器SensorEventListener之加速度傳感器,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-02-02Android 滑動(dòng)監(jiān)聽RecyclerView線性流+左右劃刪除+上下移動(dòng)
這篇文章主要介紹了Android 滑動(dòng)監(jiān)聽RecyclerView線性流+左右劃刪除+上下移動(dòng)的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09Flutter路由跳轉(zhuǎn)參數(shù)處理技巧詳解
這篇文章主要為大家介紹了Flutter路由跳轉(zhuǎn)參數(shù)處理技巧示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08詳解Android中使用Notification實(shí)現(xiàn)進(jìn)度通知欄(示例三)
這篇文章主要介紹了詳解Android中使用Notification實(shí)現(xiàn)進(jìn)度通知欄(示例三),具有一定的參考價(jià)值,有興趣的可以了解一下。2016-12-12Android自定義View繪圖實(shí)現(xiàn)拖影動(dòng)畫
這篇文章主要介紹了Android自定義View繪圖實(shí)現(xiàn)拖影動(dòng)畫,,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09