在我的项目中,使用 onTouchEvent 检测屏幕上的触摸并相应地执行操作,并使用 viewPager 进行滑动操作。问题在于滑动触摸动作正在执行。所以从这里找到解决方案解决了它。但是我的新问题是一旦 TouchEvent.Action_up 被执行,触摸就会被禁用。代码如下:
parent.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction())
{
case MotionEvent.ACTION_MOVE:
awesomePager.requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
awesomePager.requestDisallowInterceptTouchEvent(true);
if(flag)
{
upperdock.setClickable(false);
upperdock.bringToFront();
tocparent.bringToFront();
tocbottom.bringToFront();
upperdock.setVisibility(RelativeLayout.VISIBLE);
tocparent.setVisibility(LinearLayout.VISIBLE);
tocbottom.setVisibility(LinearLayout.VISIBLE);
flag=false;
}
else
{
parent.bringToFront();
upperdock.setVisibility(RelativeLayout.INVISIBLE);
tocparent.setVisibility(LinearLayout.INVISIBLE);
tocbottom.setVisibility(LinearLayout.INVISIBLE);
flag=true;
}
break;
case MotionEvent.ACTION_CANCEL:
awesomePager.requestDisallowInterceptTouchEvent(false);
break;
default:
break;
}
return false;
}
});
在上面的代码中,如果我返回 false Action_up 没有得到执行..如果我返回 true Action_cancel 没有得到执行..那是按值传递是那里的问题。