我创建了滑动图像功能。它在nexus和小屏幕手机上运行良好。但是当我在7'标签或10'屏幕上运行时,它会抛出nosuchmethod错误(event.getAxisValue):下面是代码
public boolean onTouchEvent(MotionEvent event) {
float endXValue = 0;
//ERROR is THROWING ON THIS LINE
float x1 = event.getAxisValue(MotionEvent.AXIS_X);
int action = MotionEventCompat.getActionMasked(event);
switch (action) {
case (MotionEvent.ACTION_DOWN):
startXValue = event.getAxisValue(MotionEvent.AXIS_X);
return true;
case (MotionEvent.ACTION_UP):
endXValue = event.getAxisValue(MotionEvent.AXIS_X);
if (endXValue > startXValue) {
if (endXValue - startXValue > 100) {
System.out.println("Left-Right");
count--;
int imageId = getImageViewId("prev");
imageView.setImageResource(imageId);
}
}else {
if (startXValue -endXValue> 100) {
System.out.println("Right-Left");
int imageId = getImageViewId("next");
imageView.setImageResource(imageId);
count++;
}
}
return true;
default:
return super.onTouchEvent(event);
}
}
我正在使用API19