Can't scroll over image in webview

前端 未结 4 626
北海茫月
北海茫月 2021-01-21 22:25

I developed a webview app for android and iOS. I noticed that I can\'t scroll over a specific html element in the android app, while it works on iOS.

This is the website

4条回答
  •  一生所求
    2021-01-21 22:56

    Try to add webview in this sample..

      
    
                
    
        //  add Webview here
    
         
    
            
    

    NestedScrollViewHome.java

    public class NestedScrollViewHome  extends NestedScrollView {
        @SuppressWarnings("unused")
        private int slop;
        @SuppressWarnings("unused")
        private float mInitialMotionX;
        @SuppressWarnings("unused")
        private float mInitialMotionY;
        public NestedScrollViewHome(Context context) {
            super(context);
            init(context);
        }
    
        private boolean enableScrolling = true;
    
        public boolean isEnableScrolling() {
            return enableScrolling;
        }
    
        public void setEnableScrolling(boolean enableScrolling) {
            this.enableScrolling = enableScrolling;
        }
    
    
        private void init(Context context) {
            ViewConfiguration config = ViewConfiguration.get(context);
            slop = config.getScaledEdgeSlop();
        }
        public NestedScrollViewHome(Context context, AttributeSet attrs) {
            super(context, attrs);
            init(context);
        }
        public NestedScrollViewHome(Context context, AttributeSet attrs,
                                  int defStyleAttr) {
            super(context, attrs, defStyleAttr);
            init(context);
        }
        private float xDistance, yDistance, lastX, lastY;
        @SuppressWarnings("unused")
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
          if (isEnableScrolling())
          {
              final float x = ev.getX();
              final float y = ev.getY();
              switch (ev.getAction()) {
                  case MotionEvent.ACTION_DOWN:
                      xDistance = yDistance = 0f;
                      lastX = ev.getX();
                      lastY = ev.getY();
                      // This is very important line that fixes
                      computeScroll();
                      break;
                  case MotionEvent.ACTION_MOVE:
                      final float curX = ev.getX();
                      final float curY = ev.getY();
                      xDistance += Math.abs(curX - lastX);
                      yDistance += Math.abs(curY - lastY);
                      lastX = curX;
                      lastY = curY;
                      if (xDistance > yDistance) {
                          return false;
                      }
              }
              return super.onInterceptTouchEvent(ev);
          }else
              return false;
        }
        public interface OnScrollChangedListener {
            void onScrollChanged(NestedScrollView who, int l, int t, int oldl,
                                 int oldt);
        }
        private OnScrollChangedListener mOnScrollChangedListener;
        public void setOnScrollChangedListener(OnScrollChangedListener listener) {
            mOnScrollChangedListener = listener;
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            if (isEnableScrolling()) {
                return super.onTouchEvent(ev);
            } else {
                return false;
            }
        }
    
        @Override
        protected void onScrollChanged(int l, int t, int oldl, int oldt) {
            super.onScrollChanged(l, t, oldl, oldt);
            if (mOnScrollChangedListener != null) {
                mOnScrollChangedListener.onScrollChanged(this, l, t, oldl, oldt);
            }
        }
    }
    

提交回复
热议问题