简体   繁体   English

如何知道ListView的最后一行是否完全显示?

[英]How to know if the last row of the ListView is displayed fully?

I know how to check if the last row of the ListView is visible. 我知道如何检查ListView的最后一行是否可见。 However, being visible doesn't guarantee that the row is displayed fully. 但是,可见并不能保证行完全显示。 How can I check if the last row is displayed fully? 如何检查最后一行是否完整显示?

The solution is to compare the height of the ListView to the bottom position of the footer. 解决方案是将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();
        }
    }
}

For the interest of others, the footer is basically a View which I added to the ListView via the addFooterView . 为了他人的兴趣,页脚基本上是一个View ,我通过addFooterView添加到ListView R.layout.footer is the layout for the footer. R.layout.footer是页脚的布局。 Below is a sample code on how I initialize the footer and added it on the ListView : 下面是我如何初始化页脚并将其添加到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);

I'd try something like (not tested): 我会尝试类似(未测试)的东西:

if (listView.getScrollY() == listView.getMaxScrollAmount()) {
    // ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM