Automatic vertical scrolling TextView with text containing a link to the site

I created a TextView where the text automatically starts scrolling vertically, for example, at the end of the movie. The text has a link to the site. The text scrolls smoothly and the link opens a web browser.

However, when you click a link, the text starts to scroll back down to the bottom of the TextView, where it stops.

I want the text to keep scrolling, even if I click the link. What to do?

Text field (activity_main.xml):

<TextView android:id="@+id/text_box" android:layout_width="match_parent" android:layout_height="wrap_content" android:maxLines="6" android:text="@string/text" /> 

Scrolling text (strings.xml):

 <string name="text"> bla bla\nlotsa bla\n\n<a href="http://www.stackoverflow.com">stackoverflow.com</a> </string> 

Text box and scroller (MainActivity.java):

 private TextView mTextBox; private Scroller mTextScroller; mTextBox = (TextView) findViewById(R.id.text_box); mTextBox.setMovementMethod(LinkMovementMethod.getInstance()); // Making the link clickable mTextScroller = new Scroller(this, new LinearInterpolator()); // Create new scroller mTextBox.setScroller(mTextScroller); // Set the scroller to the text view 

To start scrolling text (MainActivity.java):

 int startY = mTextBox.getHeight(); int lineHeight = mTextBox.getLineHeight(); int lineCount = mTextBox.getLineCount(); int duration = 10000; // Milliseconds int startX = 0; int dx = 0; int dy = startY + lineHeight * lineCount; mTextScroller.startScroll(startX, -startY, dx, dy, duration); 
+6
source share
1 answer

The solution may be to place the button in front of the TextView and setOnClickListener () for the button so that the TextView does not get any interaction. I think the problem is due to the TextView changing when clicking on it. I may be wrong, but you can try this approach

0
source

Source: https://habr.com/ru/post/974623/


All Articles