【发布时间】:2013-07-09 07:56:16
【问题描述】:
单击按钮时,我试图在列表视图中发送数据。
但是,我的列表视图一次显示 2 行,一个完整行和一个部分行。有没有办法我可以确定哪一行显示部分显示,哪一行显示完全。
我能够获得仅显示的索引。还有其他方法吗?
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == SCROLL_STATE_IDLE){
Rect r = new Rect ();
View child = recordListview.getChildAt(view.getFirstVisiblePosition()); // first visible child
if (child == null)
return;
double height = child.getHeight () * 1.0;
recordListview.getChildVisibleRect (child, r, null);
Log.d("Visible1 ", view.getFirstVisiblePosition() + " " + height + " " + r.height() );
if (Math.abs (r.height ()) < height / 2.0) {
// show next child
recordListview.smoothScrollToPosition(view.getFirstVisiblePosition()+1);
Log.d("Visible1 Location", view.getFirstVisiblePosition() +1+ "");
}
else {
recordListview.smoothScrollToPosition(view.getFirstVisiblePosition());
Log.d("Visible1 Location", view.getFirstVisiblePosition()+ "");
}
}
}
});
【问题讨论】:
-
你试过 getChildVisibleRect() 吗?
-
@sandrstar 我已经用stackoverflow.com/questions/15338509/… 中显示的示例更新了我的代码。这会导致我的列表视图不再可滚动。
-
是否调用了 onScroll()?我认为您需要使用 onScrollStateChanged(),检测 SCROLL_STATE_IDLE,然后执行您的逻辑。
-
@sandrstar 是的 onscrolled 被解雇了。但是,r.height 始终为零。