Created
October 4, 2012 15:49
-
-
Save chrisbanes/3834527 to your computer and use it in GitHub Desktop.
Fail-safe way of getting first visible child
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Obviously the
getTop()
could be extracted to a variable for optimisation, etc.