我知道如何检查ListView的最后一行是否可见。但是,可见并不能保证行完全显示。如何检查最后一行是否完整显示?
答案 0 :(得分:5)
解决方案是将ListView的高度与页脚的底部位置进行比较。
public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3)
{
if(arg1 + arg2 == arg3) //If last row is visible. In this case, the last row is the footer.
{
if(footer != null) //footer is a variable referencing the footer view of the ListView. You need to initialize this onCreate
{
if(listView.getHeight() == footer.getBottom()) //Check if the whole footer is visible.
doThisMethod();
}
}
}
为了他人的兴趣,页脚基本上是View
,我通过ListView
添加到addFooterView
。 R.layout.footer
是页脚的布局。下面是关于如何初始化页脚并将其添加到ListView
:
View footer; //This is a global variable.
....
//Inside onCreate or any method where you initialize your layouts
footer = getLayoutInflater().inflate(R.layout.footer, null);
listView.addFooterView(footer);
答案 1 :(得分:0)
我会尝试类似(未经测试)的事情:
if (listView.getScrollY() == listView.getMaxScrollAmount()) {
// ...
}