void scrollToVisible(int targetPos,int boundPos,int duration){
  final int firstPos=mFirstPosition;
  final int childCount=getChildCount();
  final int lastPos=firstPos + childCount - 1;
  final int paddedLeft=mListPadding.left;
  final int paddedRight=getWidth() - mListPadding.right;
  if (targetPos < firstPos || targetPos > lastPos) {
    Log.w(TAG,"scrollToVisible called with targetPos " + targetPos + " not visible ["+ firstPos+ ", "+ lastPos+ "]");
  }
  if (boundPos < firstPos || boundPos > lastPos) {
    boundPos=INVALID_POSITION;
  }
  final View targetChild=getChildAt(targetPos - firstPos);
  final int targetLeft=targetChild.getLeft();
  final int targetRight=targetChild.getRight();
  int scrollBy=0;
  if (targetRight > paddedRight) {
    scrollBy=targetRight - paddedRight;
  }
  if (targetLeft < paddedLeft) {
    scrollBy=targetLeft - paddedLeft;
  }
  if (scrollBy == 0) {
    return;
  }
  if (boundPos >= 0) {
    final View boundChild=getChildAt(boundPos - firstPos);
    final int boundLeft=boundChild.getLeft();
    final int boundRight=boundChild.getRight();
    final int absScroll=Math.abs(scrollBy);
    if (scrollBy < 0 && boundRight + absScroll > paddedRight) {
      scrollBy=Math.max(0,boundRight - paddedRight);
    }
 else     if (scrollBy > 0 && boundLeft - absScroll < paddedLeft) {
      scrollBy=Math.min(0,boundLeft - paddedLeft);
    }
  }
  smoothScrollBy(scrollBy,duration);
}

void scrollToVisible ( int targetPos , int boundPos , int duration ) { final int firstPos = mFirstPosition ; final int childCount = getChildCount ( ) ; final int lastPos = firstPos + childCount - 1 ; final int paddedLeft = mListPadding . left ; final int paddedRight = getWidth ( ) - mListPadding . right ; if ( targetPos < firstPos || targetPos > lastPos ) { Log . w ( TAG , "scrollToVisible called with targetPos " + targetPos + " not visible [" + firstPos + ", " + lastPos + "]" ) ; } if ( boundPos < firstPos || boundPos > lastPos ) { boundPos = INVALID_POSITION ; } final View targetChild = getChildAt ( targetPos - firstPos ) ; final int targetLeft = targetChild . getLeft ( ) ; final int targetRight = targetChild . getRight ( ) ; int scrollBy = 0 ; if ( targetRight > paddedRight ) { scrollBy = targetRight - paddedRight ; } if ( targetLeft < paddedLeft ) { scrollBy = targetLeft - paddedLeft ; } if ( scrollBy == 0 ) { return ; } if ( boundPos >= 0 ) { final View boundChild = getChildAt ( boundPos - firstPos ) ; final int boundLeft = boundChild . getLeft ( ) ; final int boundRight = boundChild . getRight ( ) ; final int absScroll = Math . abs ( scrollBy ) ; if ( scrollBy < 0 && boundRight + absScroll > paddedRight ) { scrollBy = Math . max ( 0 , boundRight - paddedRight ) ; } else if ( scrollBy > 0 && boundLeft - absScroll < paddedLeft ) { scrollBy = Math . min ( 0 , boundLeft - paddedLeft ) ; } } smoothScrollBy ( scrollBy , duration ) ; }
scroll such that targetpos is in the visible padded region without scrolling boundpos out of view . assumes targetpos is onscreen .
