I have a GridView that shows images from your gallery. When user scrolls the list, details about the image animate in from the left. I implemented this in the class that defines custom layout for the GridView item. It extends LinearLayout.
OnScrollChangedListener mScrollListener = new OnScrollChangedListener() {
@Override
public void onScrollChanged() {
if (!getGlobalVisibleRect(r)) {
resetAnimation();
} else {
if (checkBounds()) {
showInfo();
}
} else {
hideInfo();
}
Method resetAnimation() resets the animation if it's view is not visible on screen. Method checkBounds() compares the Rect got with getGlobalVisibleRect(r) and the Rect representing the screen to check if the details View should be shown.
I add the listener in onFinishInflate() like this:
getViewTreeObserver().addOnScrollChangedListener(mScrollListener);
Now the actual issue:
Everything works fine on API 19, API 18, API 17 and API 13, tested both on real devices and emulators. On API 14 (Android 4.0.1 and 4.0.2) the onScrollChanged() never gets fired, both on physical device and emulator.
Is it a bug or am I missing something?
Instead of
OnScrollChangedListener
, could you try withOnScrollListener
...I don't know why it is not firing in 4.0, but you could try with this...