android listview 判断最后一行,android – 如何知道ListView的最后一行是否完全显示?...

这篇博客介绍了如何在Android中利用ListView的滚动事件检测页脚是否完全可见。通过比较ListView的高度与页脚底部的位置,可以在页脚完全显示时触发特定方法。示例代码展示了如何初始化和添加页脚视图,并在ListView滚动到底部时执行特定操作。
摘要由CSDN通过智能技术生成

解决方案是将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添加到ListView. 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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值