viewPager.setOnTouchListener(
new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
moved = false;
System.out.println("clicked ACTION_DOWN");
}
if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
System.out.println("clicked ACTION_MOVE");
moved = true;
}
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
if (!moved) {
System.out.println("clicked ACTION_UP");
view.performClick();
}
}
return false;
}
}
);
并添加了onclick监听器,如下所示
viewPager.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
}
}
);
它在samsug手机中运行良好,但华为手机不会触发MotionEvent.ACTION_UP。有人可以帮忙吗?
答案 0 :(得分:0)
我通过使用GestureDetector
解决了这个问题GestureDetector tapGestureDetector = new GestureDetector(getActivity(), new TapGestureListener());
使用以下代码来处理此问题:
class TapGestureListener extends GestureDetector.SimpleOnGestureListener{
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// Your Code here
System.out.println("hello");
if (e.getAction() == MotionEvent.ACTION_DOWN) {
moved = false;
viewPager.performClick();
System.out.println("clicked ACTION_DOWN");
}
if (e.getAction() == MotionEvent.ACTION_MOVE) {
System.out.println("clicked ACTION_MOVE");
moved = true;
}
if (e.getAction() == MotionEvent.ACTION_UP) {
if (!moved) {
System.out.println("clicked ACTION_UP");
}
}
return false;
}
}
}
setOnclickListener将在此处正常工作
viewPager.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
}
}
);