• 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;
    	}
    
    }


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

  • 相关阅读:
    取得GridPanel选定行所有字段值
    从少林寺的核心竞争力看软件作坊和正规军的差异
    估算软件项目成本
    Delphi FastReport报表常用方法
    少林寺的组织结构分析
    embed标签使用
    C# 多种方式播放Wav声音
    js 关闭浏览器
    ExtJS GridPanel根据条件改变字体颜色
    [Jsp] 如何在JSP页面快速输出从Servlet接收的数据_看JSTL常用C标签的威力
  • 原文地址:https://www.cnblogs.com/riskyer/p/3333777.html
Copyright © 2020-2023  润新知