6
votes

I've made a TextView where the text automatically starts scrolling vertical, like the end credits in a movie. In the text there's a link to a website. The text scrolls smoothly and the link opens the web browser.

However, when the link is clicked, the text starts scrolling backwards, down to the bottom of the TextView, where it stops.

I want the text to continue scrolling, even if the link is clicked. What to do?

The text box layout (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" />

The text to be scrolled (strings.xml):

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

The 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 make the text start scrolling (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);
1

1 Answers

0
votes

A solution might be to place a Button in front of the TextView and do setOnClickListener() for the button so that the TextView does not receive interaction. I think the problem is with the focus of the TextView changing when tapping on it. I might be wrong but you could try this approach