获取有关lListView全部爆满可见对象 [英] Get all full visible objects on lListView
问题描述
我有一个ListView,它包含多个元素,然后我可以在一台显示器time.Now我想索引了所有的元素,这是完全可见的( - >指望他们,在这里我只能看到一点底或该项目的顶部)。
这时我用 getFirstVisiblePosition()
&放大器; getLastVisiblePosition()
到 for循环
来迭代他们,但这些方法是不准确的,因为我想。
I have a ListView, which contains more elements then I can display at one time.Now I want to get Index off all Elements, which are full visible ( -> expect them, where I only can see a bit of bottom or top of the item).
At this moment I use getFirstVisiblePosition()
& getLastVisiblePosition()
into an for-loop
to iterate them, but these method is not accurate as I want to.
有没有更好的解决办法?
Is there any better solution?
推荐答案
一个ListView保持它的组织在一个自上而下的列表,你可以用访问行getChildAt()
。所以,你想要什么是很简单的。让我们的第一个和最后一页查看,然后检查他们的完全的可见或不可见:
A ListView keeps its rows organized in a top-down list, which you can access with getChildAt()
. So what you want is quite simple. Let's get the first and last Views, then check if they are completely visible or not:
// getTop() and getBottom() are relative to the ListView,
// so if getTop() is negative, it is not fully visible
int first = 0;
if(listView.getChildAt(first).getTop() < 0)
first++;
int last = listView.getChildCount() - 1;
if(listView.getChildAt(last).getBottom() > listView.getHeight())
last--;
// Now loop through your rows
for( ; first <= last; first++) {
// Do something
View row = listView.getChildAt(first);
}
添加
现在我想索引了所有的元素,这是完全可见
Now I want to get Index off all Elements, which are full visible
我不能确定那是什么句话的意思。如果code以上是不是你想要的,你可以使用索引:
I'm not certain what that sentence means. If the code above isn't the index you wanted you can use:
int first = listView.getFirstVisiblePosition();
if(listView.getChildAt(0).getTop() < 0)
first++;
有一个指标是相对于您的适配器(即 adapter.getItem(第一)
)
这篇关于获取有关lListView全部爆满可见对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!