Textview scrolling not working
12,824
Solution 1
You can't have a scrollable View
, like TextView
or ListView
, inside a ScrollView
.
So use your simple TextView
inside a normal layout and add android:scrollbars
property to it.
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:lines="3"
android:scrollbars="vertical"
android:scrollbarStyle="insideOverlay"
android:fadeScrollbars="true"
android:fadingEdge="vertical" />
In the Activity
side you must write something like:
tv1.setMovementMethod(new ScrollingMovementMethod());
(Basically the same thing o described at your first point)
Solution 2
you can try it as:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/TEXT_STATUS_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
</LinearLayout>
</ScrollView>
Solution 3
<ScrollView
android:id="@+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/TEXT_STATUS_ID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
</ScrollView>
Author by
Dan Jurgen
Updated on June 05, 2022Comments
-
Dan Jurgen almost 2 years
I want to scroll text down and up vertically, incase the text to appear in the textview is longer than the space. However, the below methods I tested, do not work.
1 -
tv1.setMovementMethod(new ScrollingMovementMethod());
Moreover, upon using this method, calls toonFling()
method stop to work.2 - using
<ScrollView>
in layout XML. also, when using this method, calls toonFling()
method stop to work.<ScrollView android:id="@+id/SCROLLER_ID" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical" android:fillViewport="true"> <TextView android:id="@+id/TEXT_STATUS_ID" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1.0"/> </ScrollView>
my TextView in layout XML is the following.
<TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="2.26" android:background="@drawable/green" android:gravity="center" android:text="Large Text" android:textAppearance="?android:attr/textAppearanceLarge" />
-
Dan Jurgen over 11 yearshi @Danil. Unfortunately, it does not work. Long texts are not scrollable down and they are cut off. the onFling() method also does not work.
-
Dan Jurgen over 11 yearsdo I have to use the <linearLayout ?
-
Dan Jurgen over 11 yearswhats ur android version and what is your handset ?
-
yugidroid over 11 years@DanJurgen, you do. Make a scrollable
TextView
inside aScrollView
won't work. -
Danil Onyanov over 11 yearsi have several different devices. It doesn't important: its basic functionality. stackoverflow.com/questions/6674341/…
-
Dan Jurgen over 11 yearshi @yugidroid , I retried, it did not work. and once i apply the tv1.setMovementMethod(new ScrollingMovementMethod()); my onFling() methods which I use to swipe left/right stops to work.
-
Dan Jurgen over 11 years@yugidroid . I tried it, and it WORKS. however, the text is getting way too up or way too low. Is there any method that I can make it between two fixed lengths ? and whenever I get a new text there, the location (lets say very up) still applies to the new text.. I want it to be centered..
-
Dan Jurgen over 11 yearsthe onFling() methods, and the gestures work when you override the dispatchTouchEvent @Override public boolean dispatchTouchEvent(MotionEvent ev) { super.dispatchTouchEvent(ev); return productGestureDetector.onTouchEvent(ev); }