Android的定制库禁用滚动 [英] Android Custom gallery to disable scrolling

查看:148
本文介绍了Android的定制库禁用滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个自定义库,以禁用滚动。 如何禁用图库查看滚动 <:我已经得到了这个以下/ P>

I'm attempting to create a custom Gallery to disable scrolling. I've got the following from this: how to disable gallery view scrolling

 public class MyGallery extends Gallery{


public MyGallery(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){
    if (isSelected())
        return true;
    else return super.onFling(e1, e2, velocityX, velocityY);
    }

}

好像没有奏效。我究竟做错了什么?

Doesn't seem to be working. What am I doing wrong?

推荐答案

注意如果(isSelected())例如在子句中,你可能想省略与回报无条件,完全避免继承的实现。

Note the if (isSelected()) clause in example, you might want to omit that and return true unconditionally, completely avoiding inherited implementation.

重写 onFling prevents甩但不影响常规滚动,用手指向下。要做到这一点,试试也覆盖 onScroll ,并立即从那里返回true。

Overriding onFling prevents flings but doesn't affect regular scrolling, with finger down. To do that, try also overriding onScroll and immediately returning true from there.

如果不工作,要么,你也可以覆盖的onTouchEvent 和过滤器的触摸事件出现。

If that doesn't work either, you can also override onTouchEvent and filter touch events there.

这篇关于Android的定制库禁用滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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