On some Android devices (LG Google Nexus 5 with Android L and M) a TextView with android:ellipsize="marquee" and padding results in the text overflowing the textview. It occurs on the right side but not on the left side of the TextView, though, while the padding is applied to both the left and the right side.
It does not occur on Samsung Galaxy S3 and S6 with Android K and L, respectively.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:freezesText="true"
android:alpha="0.85"
android:background="@color/by433_gray_darker"
android:textColor="@color/white"
android:textSize="11sp" />
What can I do to fix or work around this?
Android TextView ellipsize property Causes words in the text that are longer than the view's width to be ellipsized ( means to shorten text using an ellipsis, i.e. three dots …) instead of broken in the middle to fit it inside the given view.
Here we have used android:ellipsize=”marquee” to add a marquee to our text and android:singleLine=”true” so that our text will show only in one line.
you should use this: myText. setVisibility(View. INVISIBLE);
gpetuhov/textview_limit_text. txt. This will limit number of lines to 1 and if text exceeds limit, TextView will display ... in the end of line.
Your issue is a bug of Android and already reported and assigned on Android Open Source Project:
Your workaround may look like this:
<FrameLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:layout_marginBottom="1dp"
android:background="@color/by433_gray_darker">
<TextView
android:id="@+id/textId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:freezesText="false"
android:alpha="0.85"
android:text="super nice text text text text text text text text text text text text text text text text text"
android:textColor="@color/white"
android:textSize="11sp" />
</FrameLayout>
So, the idea is to have a wrapper container with paddings, margins and background. (It shouldn't be much of performance overhead, if you have only couple of such views)
Original incorrect answer (Though there were two TextViews) The issue might be due to combination of so many attributes on your TextView. Here are some suggestions:
From your layout it seems that you can try something like this instead of "match_parent" on your text views:
<LinearLayout android:orientation="horizontal" ...>
<TextView android:layout_width="0dp" android:layout_weight="1" ... />
<TextView android:layout_width="0dp" android:layout_weight="1" ... />
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With