Android的定制库禁用滚动Android

由网友(怪味小萝莉)分享简介:我试图创建一个自定义库,以禁用滚动。 如何禁用图库查看滚动 I'm attempting to create a custom Gallery to disable scrolling. I've got the following from this: how to disable gallery view scro...

我试图创建一个自定义库,以禁用滚动。 如何禁用图库查看滚动

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.

阅读全文

相关推荐

最新文章