A horizontally scrollable TextView shows inconsistent behavior in Android versions

I have a text view that has one aligned Arabic (right to left) text. The content of the text increases in time, and the last (leftmost) part should always be displayed. First, the horizontal scroll bar is set to the right, and when you scroll the text, it automatically scrolls to the left.

This code works fine on an Android 2.3 phone. This comes from layout.xml

<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="none" android:fadingEdge="horizontal" android:gravity="right" android:scrollHorizontally="true" android:scrollbars="horizontal" android:singleLine="true" android:text="@string/txt_start" android:textAppearance="?android:attr/textAppearanceLarge" /> 

I have it in the onCreate () method of my activity

 tv = (TextView) findViewById(R.id.textView1); tv.setMovementMethod(new ScrollingMovementMethod()); 

The problem is the inconsistent behavior of the text view on phones with Android 4.0+. The horizontal scrollbar does not fit right first, so the TextView is initially empty! If I try to scroll through empty text, text will appear. When additional text is added, the scroll bar does not scroll to display the new text, but if I manually scroll the text, it appears.

I searched stackoverflow and tried to add the following properties without success.

 android:focusable="true" android:focusableInTouchMode="true" 
+4
source share
3 answers

He found that Left / Right gravity is out of date, the developer should use Start / End. To scroll through the text, it is necessary that the "wrap_content" parameter be set to its width, in addition, for textDirection, you must set the RTL. For unknown reasons, textDirection did not work programmatically, but worked in xml.

This code works well in all versions of the Android API.

  <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="end" android:textDirection="rtl" android:scrollHorizontally="true" android:scrollbars="horizontal" android:singleLine="true" android:ellipsize="none" android:text="@string/txt_start" android:textAppearance="?android:attr/textAppearanceLarge" /> 
0
source

Try this example, it should work:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/myText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/myscroll" android:ellipsize="marquee" android:singleLine="true" android:scrollHorizontally="true" android:marqueeRepeatLimit="10" > </LinearLayout> 

Note : when testing the selection area, do not check it in the design view inside Eclipse, try on the \ device emulator.

Also, if you want to add a scroll effect to the code:

 TextView tView = (TextView) findViewById(R.id.myText); tView.stSelected(true); 

To make the frame scroll without stopping at the end of the selection area:

 android:marqueeRepeatLimit="marquee_forever" 
0
source

None of these solutions worked in my case when I wanted to animate the scroll of a TextView using android:gravity="right" . A simple workaround that helped keep the TextView texture to the left, but put it to the right inside the RelativeLayout container:

 <RelativeLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <AutoScrollingTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:gravity="left" android:singleLine="true" android:ellipsize="none"> </RelativeLayout> 
0
source

All Articles