gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:52:31 25 4
gpt4 key购买 nike

我知道如何检查 ListView 的最后一行是否可见。但是,可见并不能保证该行完全显示。如何检查最后一行是否完整显示?

最佳答案

解决方案是比较 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,我通过 addFooterView 添加到 ListViewR.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);

关于android - 如何知道ListView的最后一行是否显示完整?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9289792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com