@@ -35,22 +35,30 @@ private Touch() { }
3535 * Y position.
3636 */
3737 public static void scrollTo (TextView widget , Layout layout , int x , int y ) {
38- final int verticalPadding = widget .getTotalPaddingTop () + widget .getTotalPaddingBottom ();
39- final int top = layout .getLineForVertical (y );
40- final int bottom = layout .getLineForVertical (y + widget .getHeight () - verticalPadding );
38+ final int horizontalPadding = widget .getTotalPaddingLeft () + widget .getTotalPaddingRight ();
39+ final int availableWidth = widget .getWidth () - horizontalPadding ;
4140
42- int left = Integer .MAX_VALUE ;
43- int right = 0 ;
41+ final int top = layout .getLineForVertical (y );
4442 Alignment a = layout .getParagraphAlignment (top );
4543 boolean ltr = layout .getParagraphDirection (top ) > 0 ;
4644
47- for (int i = top ; i <= bottom ; i ++) {
48- left = (int ) Math .min (left , layout .getLineLeft (i ));
49- right = (int ) Math .max (right , layout .getLineRight (i ));
45+ int left , right ;
46+ if (widget .getHorizontallyScrolling ()) {
47+ final int verticalPadding = widget .getTotalPaddingTop () + widget .getTotalPaddingBottom ();
48+ final int bottom = layout .getLineForVertical (y + widget .getHeight () - verticalPadding );
49+
50+ left = Integer .MAX_VALUE ;
51+ right = 0 ;
52+
53+ for (int i = top ; i <= bottom ; i ++) {
54+ left = (int ) Math .min (left , layout .getLineLeft (i ));
55+ right = (int ) Math .max (right , layout .getLineRight (i ));
56+ }
57+ } else {
58+ left = 0 ;
59+ right = availableWidth ;
5060 }
5161
52- final int hoizontalPadding = widget .getTotalPaddingLeft () + widget .getTotalPaddingRight ();
53- final int availableWidth = widget .getWidth () - hoizontalPadding ;
5462 final int actualWidth = right - left ;
5563
5664 if (actualWidth < availableWidth ) {
@@ -166,16 +174,24 @@ public static boolean onTouchEvent(TextView widget, Spannable buffer,
166174 return false ;
167175 }
168176
177+ /**
178+ * @param widget The text view.
179+ * @param buffer The text buffer.
180+ */
169181 public static int getInitialScrollX (TextView widget , Spannable buffer ) {
170182 DragState [] ds = buffer .getSpans (0 , buffer .length (), DragState .class );
171183 return ds .length > 0 ? ds [0 ].mScrollX : -1 ;
172184 }
173-
185+
186+ /**
187+ * @param widget The text view.
188+ * @param buffer The text buffer.
189+ */
174190 public static int getInitialScrollY (TextView widget , Spannable buffer ) {
175191 DragState [] ds = buffer .getSpans (0 , buffer .length (), DragState .class );
176192 return ds .length > 0 ? ds [0 ].mScrollY : -1 ;
177193 }
178-
194+
179195 private static class DragState implements NoCopySpan {
180196 public float mX ;
181197 public float mY ;
0 commit comments