android跑馬燈出現(xiàn)重復跳動以及不滾動問題的解決方法
android跑馬燈出現(xiàn)重復跳動、不滾動問題,本文給出解決方案,供大家參考。
原因:頁面有View被重新繪制了、焦點被搶占
例如:
1、TextView 的width被設置為wrap_content,setText()時內(nèi)容改變會導致View重新繪制;
2、頁面中動態(tài)生成View同樣會影響跑馬燈效果;
解決辦法:
1.盡可能的將頁面的View的寬和高設置為固定值,盡量不要動態(tài)去修改
2.自定義TextView 重寫isFocused()函數(shù),讓他放回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);
}
}
}
小編之前還看到一個關(guān)于android跑馬燈重復抖動的解決方法,也分享給大家,謝謝原作者的分享
先貼一下TextView跑馬燈的實現(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)的問題,在界面上,有一個用viewPager實現(xiàn)的廣告輪播功能,發(fā)現(xiàn)每次切換廣告的時候,跑馬燈會跳動,并且從頭顯示,以為是viewPager與跑馬燈沖突,后來在網(wǎng)上搜了一下,android 6.0有時候會出現(xiàn)這個問題,解決的方法,在跑馬燈控件外層,再嵌套一個布局控件
<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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Android 中TextView中跑馬燈效果的實現(xiàn)方法
- Android TextView實現(xiàn)跑馬燈效果的方法
- Android實現(xiàn)跑馬燈效果的方法
- Android自定義View實現(xiàn)豎直跑馬燈效果案例解析
- Android實現(xiàn)圖文垂直跑馬燈效果
- Android自定義textview實現(xiàn)豎直滾動跑馬燈效果
- Android中使用TextView實現(xiàn)文字跑馬燈效果
- Android基于TextView不獲取焦點實現(xiàn)跑馬燈效果
- Android跑馬燈MarqueeView源碼解析
- android自定義View實現(xiàn)跑馬燈效果
相關(guān)文章
Android傳感器SensorEventListener之加速度傳感器
今天小編就為大家分享一篇關(guān)于Android傳感器SensorEventListener之加速度傳感器,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-02-02
Android 滑動監(jiān)聽RecyclerView線性流+左右劃刪除+上下移動
這篇文章主要介紹了Android 滑動監(jiān)聽RecyclerView線性流+左右劃刪除+上下移動的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-09-09
Flutter路由跳轉(zhuǎn)參數(shù)處理技巧詳解
這篇文章主要為大家介紹了Flutter路由跳轉(zhuǎn)參數(shù)處理技巧示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08
詳解Android中使用Notification實現(xiàn)進度通知欄(示例三)
這篇文章主要介紹了詳解Android中使用Notification實現(xiàn)進度通知欄(示例三),具有一定的參考價值,有興趣的可以了解一下。2016-12-12

