Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View only registering MotionEvent.ACTION_DOWN

I'm having an interesting problem...that I can't seem to find the solution for. I'm using an ObjectAnimator to rotate an ImageView; but the onTouchListener only seems to be registering MotionEvent.ACTION_DOWN. (I deduced this from the Log Cats, there is also MotionEvent.ACTION_MOVE and MotionEvent.ACTION_UP).

I thought maybe the problem had to do with trying to listen and animate to a veiw at the same time. I wrapped both the imageview and a linear layout (set to MATCH PARENT) in a relative layout, and registered the linear layout to listen for touch events. The Linear Layout is having the same problem; only MotionEvent.ACTION_UP is being handled. Is there something I need to go to get MotionEvent.ACTION_MOVE to be registered?

Here is my code:

            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;
}

(Sorry about the poorly formatted code...)

like image 310
user1164429 Avatar asked May 12 '12 13:05

user1164429


1 Answers

return false;  

changed to return true;

like image 151
Changwei Yao Avatar answered Nov 03 '22 00:11

Changwei Yao