How can I bring the item in front off the screen on stop scrolling automatically with animation.Currently it works with following code but it perform very fast with scroll.
So my requirement is to perform this with animation so user can see sliding of listview.
Below is my code,but I did not get expected result.
listview.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == SCROLL_STATE_IDLE) {
View child = layout.getChildAt(0); // first visible child
Rect r = new Rect(0, 0, child.getWidth(), child.getHeight()); // set this initially, as required by the docs
double height = child.getHeight() * 1.0;
layout.getChildVisibleRect(child, r, null);
if (Math.abs(r.height()) != height)
{
//only smooth scroll when not scroll to correct position
if (Math.abs(r.height()) < height / 2.0)
{
listview.postDelayed(new Runnable() {
@Override
public void run() {
listview.smoothScrollBy(listview.getFirstVisiblePosition(), 10000);
}
}, 500);
} else if (Math.abs(r.height()) > height / 2.0)
{
listview.postDelayed(new Runnable() {
@Override
public void run() {
listview.smoothScrollBy(listview.getFirstVisiblePosition(), 10000);
}
}, 500);
} else
{
listview.postDelayed(new Runnable() {
@Override
public void run() {
listview.smoothScrollBy(listview.getFirstVisiblePosition(),10000);
}
},500);
}
}
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});