Android, RelativeLayout restarts Marquee-TextView when changing ImageView in same RelativeLayout

后端 未结 4 1223
星月不相逢
星月不相逢 2021-01-18 20:29

I have not found a solution for my problem, maybe you can help me here.

I am using a RelativeLayout with an ImageView and a TextView as children. The TextView contai

相关标签:
4条回答
  • 2021-01-18 20:48

    just a simple Fix..:) no need to worry much...just fix width of textview as some 800dp or too higher width. it will solve reset issue

        <TextView
        android:id="@+id/adv_txt_view"
        android:layout_width="800dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:singleLine="true"
        android:ellipsize="marquee"                               
    
        android:fadingEdge="horizontal"
        android:marqueeRepeatLimit="marquee_forever"                           
        android:focusableInTouchMode="true"                           
        android:focusable="true"                     
        android:scrollHorizontally="true"                       
        android:textColor="@color/black"
        android:text="large text to scroll!!" />
    
    0 讨论(0)
  • 2021-01-18 20:52

    I had a same problem and I fixed it just now:)

    If your TextView which in layout XML contains layout_weight

    android:layout_weight="1"
    

    Remove it!This attibute cause marquee restart.

    Hope helpful:)

    0 讨论(0)
  • 2021-01-18 20:52

    See my answer here : https://stackoverflow.com/a/13841982/1823503

    The idea is :

    • to fix the width and height programmatically (you did it)
    • to setSelected (you did it)
    • to Override your TextView to fix the focus problems
    0 讨论(0)
  • 2021-01-18 20:57

    The marquee reset problem is because of loss of focus of the TextView on which it is running. To overcome these issues you can simply surround your TextView with another RelativeLayout so that it is in a different ViewGroup as your other views.

    You have another option: Create a new class that is a subclass of TextView and override onFocusChanged and onWindowFocusChanged to prevent loss of focus for the said textview.

    That's it. Using these techniques your marquee won't restart every time another element gains focus.

    0 讨论(0)
提交回复
热议问题