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 with OnScrollListener
...
gridView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
}
});
I don't know why it is not firing in 4.0, but you could try with this...
来源:https://stackoverflow.com/questions/20833612/onscrollchanged-never-fired-on-android-4-0