2

I have a TextView on a layout configured at a fixed width and set to a single line mode. The text property is set to a string that takes much more horizontal space to display than the width of the TextView. The user interface allows for easy scrolling of the text left and right so that any given portion of the string can be seen in the View.

I would like to place small marker graphics to the right and left of the text view to show that the text on either side of the View is scrolled beyond the borders. How can I query the TextView to determine if the text string spills beyond either the left or right border?

Michael Karas
  • 248
  • 2
  • 12

1 Answers1

2

Although I haven't used it before, check out getMovementMethod() on the TextView. You should be able to get access to scrolling events through the MovementMethod.

According to the Android docs for MovementMethod:

Provides cursor positioning, scrolling and text selection functionality in a TextView.

The TextView delegates handling of key events, trackball motions and touches to the movement method for purposes of content navigation. The framework automatically selects an appropriate movement method based on the content of the TextView.

You could try extending ScrollingMovementMethod and then setting it against your TextView, like:

MyScrollingMovementMethod movementMethod = new MyScrollingMovementMethod();
mTextView.setMovementMethod(movementMethod);

And then override the onTouchEvent method of MyScrollingMovementMethod.

But, you should probably just try extending TextView to manually handle computing the scroll length. Check out this answer here: https://stackoverflow.com/a/19827071/1738090

Community
  • 1
  • 1
w3bshark
  • 2,700
  • 1
  • 30
  • 40