9

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 to onFling() method stop to work.

2 - using <ScrollView> in layout XML. also, when using this method, calls to onFling() 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" /> 

3 Answers 3

16

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)

Sign up to request clarification or add additional context in comments.

1 Comment

hi @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.
3

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> 

4 Comments

do I have to use the <linearLayout ?
@DanJurgen, you do. Make a scrollable TextView inside a ScrollView won't work.
@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..
the onFling() methods, and the gestures work when you override the dispatchTouchEvent @Override public boolean dispatchTouchEvent(MotionEvent ev) { super.dispatchTouchEvent(ev); return productGestureDetector.onTouchEvent(ev); }
1
<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> 

3 Comments

hi @Danil. Unfortunately, it does not work. Long texts are not scrollable down and they are cut off. the onFling() method also does not work.
whats ur android version and what is your handset ?
i have several different devices. It doesn't important: its basic functionality. stackoverflow.com/questions/6674341/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.