onScrollChanged()从未在Android 4.0上触发过 [英] onScrollChanged() never fired on Android 4.0

查看:197
本文介绍了onScrollChanged()从未在Android 4.0上触发过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示图库中图片的GridView。当用户滚动列表时,有关从左侧开始动画的图像的详细信息。我在定义GridView项目的自定义布局的类中实现了这个功能。它延伸 LinearLayout

  OnScrollChangedListener mScrollListener = new OnScrollChangedListener(){
@Override
public void onScrollChanged(){
if(!getGlobalVisibleRect(r)){
resetAnimation();
} else {
if(checkBounds()){
showInfo();
}
} else {
hideInfo();
}

方法 resetAnimation()视图在屏幕上不可见。方法 checkBounds()将得到的Rect与 getGlobalVisibleRect(r)进行比较,Rect表示屏幕以检查是否显示详细信息View。



我在 onFinishInflate()中添加监听器,如下所示:

  。getViewTreeObserver()addOnScrollChangedListener(mScrollListener); 

现在的实际问题是:

API 19 ,API 18,API 17和API 13,均在真实设备和仿真器上进行测试。 在API 14(Android 4.0.1和4.0.2)上,onScrollChanged()永远不会在物理设备和模拟器上被触发。

Is它是一个错误还是我错过了什么?

解决方案

而不是 OnScrollChangedListener ,你可以尝试使用 OnScrollListener ...

  gridView.setOnScrollListener新的AbsListView.OnScrollListener(){
$ b $ @覆盖
public void onScrollStateChanged(AbsListView view,int scrollState){
// TODO自动生成的方法存根


$ b @Override
public void onScroll(AbsListView view,int firstVisibleItem,
int visibleItemCount,int totalItemCount){
// TODO自动生成的方法存根

}
});

我不知道它为什么不在4.0中触发,但是您可以试试这个.. 。


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...

这篇关于onScrollChanged()从未在Android 4.0上触发过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆