zoukankan      html  css  js  c++  java
  • android中控件公用产生的冲突的解决办法

    1.ViewPager嵌套HorizontalScrollView滑动冲突的解决办法,重写ViewPager

    public class ZdyViewPage extends ViewPager {
    
    	public ZdyViewPage(Context context) {
    		super(context);
    	}
    
    	public ZdyViewPage(Context context, AttributeSet attrs) {
    		super(context, attrs);
    	}
    
    	@Override
    	protected boolean canScroll(View v, boolean arg1, int arg2, int arg3,
    			int arg4) {
    		if (v instanceof HorizontalScrollView) {
    			return true;
    		}
    		return super.canScroll(v, arg1, arg2, arg3, arg4);
    	}
    
    }


    2.ScrollView嵌套ViewPager滑动冲突的解决办法,重写ScrollView

    public class NotifyingScrollView extends ScrollView {
        private Context mContext;
        
        /*避免Scroview和ViewPager控件冲突的解决办法*/
        private boolean canScroll;
        private GestureDetector mGestureDetector;
        View.OnTouchListener mGestureListener;
    
        public NotifyingScrollView(Context context) {
            super(context);
            mContext = context;
        }
    
        public NotifyingScrollView(Context context, AttributeSet attrs) {
            super(context, attrs);
            mContext = context;
            mGestureDetector = new GestureDetector(new YScrollDetector());
            canScroll = true;
        }
    
        public NotifyingScrollView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            mContext = context;
        }
        
        /*避免Scroview和ViewPager控件冲突的解决办法*/
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if(ev.getAction() == MotionEvent.ACTION_UP)
                canScroll = true;
            return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
        }
     
        class YScrollDetector extends SimpleOnGestureListener {
            @Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                if(canScroll)
                    if (Math.abs(distanceY) >= Math.abs(distanceX))
                        canScroll = true;
                    else
                        canScroll = false;
                return canScroll;
            }
        }
    }


    3.ListView嵌套ViewPager滑动冲突的解决办法,重写ListView

    public class MyListview extends ListView {
    
    	private Context mContext;
    
    	public MyListview(Context context) {
    		super(context);
    		mContext = context;
    	}
    
    	public MyListview(Context context, AttributeSet attrs, Context mContext) {
    		super(context, attrs);
    		this.mContext = mContext;
    	}
    
    	public MyListview(Context context, AttributeSet attrs, int defStyle,
    			Context mContext) {
    		super(context, attrs, defStyle);
    		this.mContext = mContext;
    	}
    
    	@Override
    	public boolean onInterceptTouchEvent(MotionEvent ev) {
    		super.onInterceptTouchEvent(ev);
    		return false;
    	}
    
    }


    在开发中还会遇到很多的控件组合,大家有遇到过的希望都能把代码贴上来,大家共同学习!!!

  • 相关阅读:
    关于echarts
    es6数组相关操作
    日期格式化(超实用)
    vue对象深拷贝(避免对象赋值,改变一个对象的值,另一个对象也变化)
    vue在js公用文件中使用this
    VUE百度地图API调用(手机端、PC端、微信通用)
    promise与async/await
    手机端软键盘弹出又收回后,页面下方留空白、样式定位错乱或不能滚动
    移动端表格(固定首列及表头)
    VUE面试知识整理
  • 原文地址:https://www.cnblogs.com/riskyer/p/3333777.html
Copyright © 2011-2022 走看看