【问题标题】:Android Custom gallery to disable scrollingAndroid 自定义图库以禁用滚动
【发布时间】:2012-03-22 15:05:49
【问题描述】:

我正在尝试创建自定义图库以禁用滚动。我从中得到以下信息: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);
    }

}

似乎没有工作。我做错了什么?

【问题讨论】:

    标签: java android


    【解决方案1】:

    注意示例中的if (isSelected()) 子句,您可能希望省略它并无条件返回true,完全避免继承实现。

    覆盖onFling 可防止弹跳,但不会影响手指向下的常规滚动。为此,请尝试覆盖 onScroll 并立即从那里返回 true。

    如果这也不起作用,您还可以覆盖 onTouchEvent 并在那里过滤触摸事件。

    【讨论】:

      【解决方案2】:

      我在 Linearlayout 中使用了 CustomListview。并使用以下代码禁用滚动

      public void enableDisableView(View view, boolean enabled) {
              view.setEnabled(enabled);
      
              if ( view instanceof ViewGroup ) {
                  ViewGroup group = (ViewGroup)view;
      
                  for ( int idx = 0 ; idx < group.getChildCount() ; idx++ ) {
                      enableDisableView(group.getChildAt(idx), enabled);
                  }
              }
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-02-21
        • 2011-11-10
        • 1970-01-01
        • 1970-01-01
        • 2011-07-20
        • 2023-03-08
        • 1970-01-01
        相关资源
        最近更新 更多