【发布时间】:2014-06-02 20:11:39
【问题描述】:
我想当用户滚动列表视图 1 时,列表视图 2 也像列表视图 1 一样滚动(完全以像素为单位)。
我尝试通过 smoothScrollByOffset(offset) 滚动列表视图 2,
但它滚动的次数超过了列表视图 1。
不知道为什么?
smoothScrollByOffset(offset) 发生了什么或者我错过了什么?
更多信息:
滚动列表视图 2 的代码(在列表视图 1 的 onScroll 回调中):
int previsous = 0;
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
//get current position in pixel of listview 1
View c = lv1.getChildAt(0);
int scrolly = -c.getTop() + lv1.getFirstVisiblePosition() * c.getHeight();
//Difference in pixel with the last scroll
int delta = scrolly - previsous;
Log.d("scroll", "listview 1 has scrolled: " +
scrolly + "| Difference with the last " + delta);
//scroll listview 2 by delta
lv2.smoothScrollByOffset(delta);
previsous = scrolly;
}
诊断截图:
【问题讨论】:
标签: android listview android-listview