Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fail-safe way of getting first visible child
final int listViewTopPadding = mListView.getPaddingTop();
for (int i = 0, z = mListView.getChildCount(); i < z; i++) {
View child = mListView.getChildAt(i);
if (child.getTop() > (listViewTopPadding - child.getHeight()) && child.getTop() <= listViewTopPadding) {
// Bingo, we have our first visible child...
}
}
@chrisbanes

This comment has been minimized.

Copy link
Owner Author

@chrisbanes chrisbanes commented Oct 4, 2012

Obviously the getTop() could be extracted to a variable for optimisation, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment