【发布时间】:2016-03-21 07:43:00
【问题描述】:
如何在使用动画自动停止滚动时将项目从屏幕上移开。目前它适用于以下代码,但滚动执行速度非常快。
所以我的要求是使用动画来执行此操作,以便用户可以看到列表视图的滑动。
下面是我的代码,但我没有得到预期的结果。
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) {
}
});
【问题讨论】:
-
根本不起作用。
标签: java android listview android-studio