Skip to content

Instantly share code, notes, and snippets.

@chrisbanes
Created October 4, 2012 15:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisbanes/3834527 to your computer and use it in GitHub Desktop.
Save chrisbanes/3834527 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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