我遇到了一个有趣的问题……我似乎找不到解决方案。我正在使用 ObjectAnimator 来旋转 ImageView;但 onTouchListener 似乎只注册 MotionEvent.ACTION_DOWN。(我是从 Log Cats 中推断出来的,还有 MotionEvent.ACTION_MOVE 和 MotionEvent.ACTION_UP)。
我想也许这个问题与试图同时聆听和制作动画有关。我将 imageview 和线性布局(设置为 MATCH PARENT)包装在相对布局中,并注册线性布局以侦听触摸事件。线性布局也有同样的问题;只有 MotionEvent.ACTION_UP 正在处理。我需要做些什么来注册 MotionEvent.ACTION_MOVE 吗?
这是我的代码:
touch_pad = (LinearLayout) findViewById(R.id.layout_touch_capture);
touch_pad.setOnTouchListener(this);
touch_pad.requestFocus();
public boolean onTouch(View v, MotionEvent event) {
switch(v.getId()) {
case (R.id.layout_touch_capture):
long end = 0;
long start = 0;
float y = event.getY();
float y_sum = y;
float x = event.getX();
switch(event.getAction()) {
case (MotionEvent.ACTION_UP):
end = animator.getCurrentPlayTime();
Log.d("WheelActivity", "end location = " + end);
break;
case (MotionEvent.ACTION_MOVE):
Log.d("WheelActivity", "event.getY() = " + y);
y_sum += y;
animator.setCurrentPlayTime((long) (start + y_sum));
Log.d("WheelActivity", "animator play time = " animator.getCurrentPlayTime());
Log.d("WheelActivity", "animator fraction = " +
animator.getAnimatedFraction());
break;
case (MotionEvent.ACTION_DOWN):
start = animator.getCurrentPlayTime();
Log.d("WheelActivity", "start location = " + start);
break;
}
}
return false;
}
(对不起,格式不正确的代码......)