获取有关lListView全部爆满可见对象对象、全部、lListView

由网友(她是我年少时最冒险的梦@)分享简介:我有一个ListView,它包含多个元素,然后我可以在一台显示器time.Now我想索引了所有的元素,这是完全可见的( - >指望他们,在这里我只能看到一点底或该项目的顶部)。这时我用 getFirstVisiblePosition()&放大器; getLastVisiblePosition()到 for循环来迭代...

我有一个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(第一)

阅读全文

相关推荐

最新文章