public void configureListView ( ListView listView ) { this . listView = listView ; this . listView . setOnScrollListener ( new OnScrollListener ( ) { int scrollPosition ; @ Override public void onScroll ( AbsListView view , int firstVisibleItem , int visibleItemCount , int totalItemCount ) { notifyScrollToAdditionalScrollListener ( view , firstVisibleItem , visibleItemCount , totalItemCount ) ; View topChild = view . getChildAt ( 0 ) ; int newScrollPosition ; if ( topChild == null ) { newScrollPosition = 0 ; } else { newScrollPosition = view . getFirstVisiblePosition ( ) * topChild . getHeight ( ) - topChild . getTop ( ) ; } if ( Math . abs ( newScrollPosition - scrollPosition ) >= SCROLL_DIRECTION_CHANGE_THRESHOLD ) { onScrollPositionChanged ( scrollPosition , newScrollPosition ) ; } scrollPosition = newScrollPosition ; } @ Override public void onScrollStateChanged ( AbsListView view , int scrollState ) { notifyScrollStateChangedToAdditionalScrollListener ( view , scrollState ) ; } } ) ; }
Associate a ListView to listen in order to perform the translationY animation when the ListView scroll is updated . This method is going to set a OnScrollListener to the ListView passed as argument .