Solution to the Problem of android Race Lamp Repeated Beating and Non rolling

  • 2021-12-19 07:02:00
  • OfStack

android ticker appears repeated beating, not rolling problems, this article gives a solution for your reference.

Reason: The page has View redrawn and the focus is preempted

For example:

1. width of TextView is set to wrap_content, and the content change when setText () will cause View to be redrawn;
2. The dynamic generation of View in the page will also affect the horse race effect;

Solution:

1. Set the width and height of the View of the page to a fixed value as much as possible, and try not to modify it dynamically

2. Customize TextView to rewrite isFocused () function, let him put it back to true, that is, get it straight, and the focus effect will naturally come out. If this can't solve it, it won't be the focus problem.


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);
        }
    }
}

This site also saw a solution to the repeated jitter of android ticker before, and also shared it with you. Thank you for sharing the original author

First paste 1 under the TextView lantern implementation code


<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"
/>

Problems, in the interface, there is a use of viewPager to achieve advertising carousel function, found that every time the switch advertising, the lantern will beat, and from the beginning of the display, thought it was viewPager and the lantern conflict, and later on the Internet search 1, android 6.0 sometimes appear this problem, the solution, in the lantern control outer layer, nested a layout control


<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>

Related articles: