public static void scrollTo(TextView widget,Layout layout,int x,int y){
  final int horizontalPadding=widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
  final int availableWidth=widget.getWidth() - horizontalPadding;
  final int top=layout.getLineForVertical(y);
  Layout.Alignment a=layout.getParagraphAlignment(top);
  boolean ltr=layout.getParagraphDirection(top) > 0;
  int left, right;
  if (widget.getHorizontallyScrolling()) {
    final int verticalPadding=widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
    final int bottom=layout.getLineForVertical(y + widget.getHeight() - verticalPadding);
    left=Integer.MAX_VALUE;
    right=0;
    for (int i=top; i <= bottom; i++) {
      left=(int)Math.min(left,layout.getLineLeft(i));
      right=(int)Math.max(right,layout.getLineRight(i));
    }
  }
 else {
    left=0;
    right=availableWidth;
  }
  final int actualWidth=right - left;
  if (actualWidth < availableWidth) {
    if (a == Layout.Alignment.ALIGN_CENTER) {
      x=left - ((availableWidth - actualWidth) / 2);
    }
 else     if ((ltr && (a == Layout.Alignment.ALIGN_OPPOSITE)) || (!ltr && (a == Layout.Alignment.ALIGN_NORMAL)) || (a == Layout.Alignment.ALIGN_RIGHT)) {
      x=left - (availableWidth - actualWidth);
    }
 else {
      x=left;
    }
  }
 else {
    x=Math.min(x,right - availableWidth);
    x=Math.max(x,left);
  }
  widget.scrollTo(x,y);
}

public static void scrollTo ( TextView widget , Layout layout , int x , int y ) { final int horizontalPadding = widget . getTotalPaddingLeft ( ) + widget . getTotalPaddingRight ( ) ; final int availableWidth = widget . getWidth ( ) - horizontalPadding ; final int top = layout . getLineForVertical ( y ) ; Layout . Alignment a = layout . getParagraphAlignment ( top ) ; boolean ltr = layout . getParagraphDirection ( top ) > 0 ; int left , right ; if ( widget . getHorizontallyScrolling ( ) ) { final int verticalPadding = widget . getTotalPaddingTop ( ) + widget . getTotalPaddingBottom ( ) ; final int bottom = layout . getLineForVertical ( y + widget . getHeight ( ) - verticalPadding ) ; left = Integer . MAX_VALUE ; right = 0 ; for ( int i = top ; i <= bottom ; i ++ ) { left = ( int ) Math . min ( left , layout . getLineLeft ( i ) ) ; right = ( int ) Math . max ( right , layout . getLineRight ( i ) ) ; } } else { left = 0 ; right = availableWidth ; } final int actualWidth = right - left ; if ( actualWidth < availableWidth ) { if ( a == Layout . Alignment . ALIGN_CENTER ) { x = left - ( ( availableWidth - actualWidth ) / 2 ) ; } else if ( ( ltr && ( a == Layout . Alignment . ALIGN_OPPOSITE ) ) || ( ! ltr && ( a == Layout . Alignment . ALIGN_NORMAL ) ) || ( a == Layout . Alignment . ALIGN_RIGHT ) ) { x = left - ( availableWidth - actualWidth ) ; } else { x = left ; } } else { x = Math . min ( x , right - availableWidth ) ; x = Math . max ( x , left ) ; } widget . scrollTo ( x , y ) ; }
scrolls the specified widget to the specified coordinates , except constrains the x scrolling position to the horizontal regions of the text that will be visible after scrolling to the specified y position .
