TimePicker在ScrollView中滑动冲突的解决方法(更新适用于全控件的方法)

自定义新的TimePicker

重写如下方法即可:(应该也适用于其他控件)

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev)
	{
	    if (ev.getActionMasked() == MotionEvent.ACTION_DOWN)
	    {
	        ViewParent p = getParent();
	        if (p != null)
	            p.requestDisallowInterceptTouchEvent(true);
	    }

	    return false;
	}


自定义NumberPicker不适用,会取消滚动事件


更新方法:

重写其外的Linearlayout的onInterceptTouchEvent即可,控件可用普通控件

还可加入Touch事件(layout是默认没有Touch事件的),使得整个Layout的区域Touch后均不会滑动,防止误操作

完整代码:

public class CustomLinearLayout extends LinearLayout {

	public CustomLinearLayout(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public CustomLinearLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public CustomLinearLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}
	
	//请求其Parents不对Touch进行拦截
	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev)
	{
	    if (ev.getActionMasked() == MotionEvent.ACTION_DOWN)
	    {
	        ViewParent p = getParent();
	        if (p != null)
	            p.requestDisallowInterceptTouchEvent(true);
	    }

	    return false;
	}
	
	//给LinearLayout加入Touch事件,使得所有Layout区域的Touch操作均不受拦截
	//参考:http://blog.csdn.net/android_tutor/article/details/7193090
	public boolean onTouchEvent(MotionEvent ev)
	{
		return true;
	}

}

转自:http://blog.csdn.net/checkin001/article/details/8298313

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值