Android text view (weight and marquee) resetting when another view updates

I have a horizontal Linear Layout with two texts, and i want to make them both visible, but since The size of the first text may vary in size, i have 2 conditions to fulfill on this scenario:

  • In cases the first text is a long text, i want to display the texts like following: |[text1 long long lo…][text2]|
  • In cases the first text is a short text, i want to display the texts like following: |[text1][text2] |

So i decided to use the marquee repeat animation on the first text, used weight in this text to fulfill the first condition, and a wrap_content on the Linear Layout to fulfill the second condition. But this makes the marquee animation to reset when another text view is updated, which is unacceptable in my app. I’ve been trying a lot of stuff, but i don’t seems to be able to produce this behavior.

Do you guys think it’s possible to fix this problem?

Thanks for anyone who answers this question

Here’s a example code:

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/textViewFirst"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:fontFamily="@font/roboto_regular"
        android:textSize="32sp"
        android:text="May be a very very very long text view"
        android:lineHeight="37.504dp"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever" />
    <TextView
        android:id="@+id/textViewSecond"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/transparentWhite"
        android:fontFamily="@font/roboto_regular"
        android:textSize="32sp"
        android:text=" short text"
        android:lineHeight="37.504dp" />

</LinearLayout>

  • When the text is updated, it is forcing a new layout for the marquee TextView which resets the internal controls for the marquee. Unfortunately, TextView doesn’t currently permit access to how the marquee operates except for the defined API. If you want to continue scrolling of the first text view where it left off, I suggest that you write you own Scroller and attach it to the marquee TextView. You should be able to find some examples online about how to implement a scroller.

    – 

Leave a Comment