仅查看注册MotionEvent.ACTION_DOWN

时间:2012-05-12 13:32:17

标签: android ontouchlistener motion-detection touch-event

我有一个有趣的问题......我似乎无法找到解决方案。我正在使用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;
}

(抱歉格式不正确的代码......)

1 个答案:

答案 0 :(得分:13)

return false;  

已更改为return true;