1

After adding a big string in textview,how to scroll back to the initial part of the string?? i am using following textview

 <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="50sp" android:singleLine="true" android:gravity="end" android:layout_gravity="end" android:layout_marginTop="40dp"> 

how to make it scroll right to left??

4
  • any help will be appreciated.... Commented Oct 6, 2016 at 15:20
  • by calling View#scrollBy / View#scrollTo Commented Oct 6, 2016 at 16:06
  • can u elaborate more plz....am new to android.....?? Commented Oct 6, 2016 at 16:43
  • new or not new, read the docs of those methods and everything will be clear Commented Oct 6, 2016 at 16:45

1 Answer 1

1

Try this code.

<HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/scroll" > <TextView android:id="@+id/textViewId" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scrollHorizontally="true" android:text="your_big_string"/> </HorizontalScrollView> 

In you activity.java, add this

final HorizontalScrollView scrollView = (HorizontalScrollView) findViewById(R.id.scroll); scrollView.postDelayed(new Runnable() { public void run() { scrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT); } }, 100L); 
Sign up to request clarification or add additional context in comments.

6 Comments

it scrolls in default direction i.e left to right...but i want to scroll my text from right to left
i did.....but the result is same i.e it scrolls from left to right....u try it urself with my given textview in the question....may be it will help you better understanding of the problem....
The edited ans serves the purpose you asked for. didn't you remove singleline, gravity, layout_gravity from your textView? these attribute may cause problem in your case. I suggest you not to edit your textView according to my answer, just copy+paste the sample code and see if it works.
then you should add your whole xml and describe your needs more specifically (ex: why the gravity is so important?).
this is my whole xml ;).....i m creating a textview which starts adding text on press button from right side dats why gravity is important to me.after some presses the textview's text goes out of the screen.datts why i need a scroller which scrolls from right to left
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.