所以我试图让我的页面的 imageview 组件在滑动时改变。我什至无法拿起滑动手势并将其转发到手势检测器上。
在 OnFling 方法中,我无法访问这些日志语句。有什么我想念的吗?
public class Detail extends Activity implements OnClickListener{
private GestureDetector gestureDetector;
private ImageView wallpaper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gestureDetector = new GestureDetector(new MyGestureDetector());
wallpaper = (ImageView)findViewById(R.id.wallpaper);
wallpaper.setAdjustViewBounds(true);
wallpaper.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("getting", "here");
//return gestureDetector.onTouchEvent(event);
return true;
}
});
}
class MyGestureDetector extends SimpleOnGestureListener {
private static final int SWIPE_MIN_DISTANCE = 50;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
Log.d("MOTION", "STARTED");
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Log.d("Moving", "Right");
return true;
}
else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Log.d("Moving", "Left");
return true;
}
} catch (Exception e) {
}
return false;
}
}