How to do rotation animation on a RelativeLayout

684 Views Asked by At

I need to do a rotate animation on a RelativeLayout, I've used NineOldAndroid library for animation:

View v = findViewById(R.id.wrap_btnSelect);
ObjectAnimator t1 = ObjectAnimator.ofFloat(
        v, "rotation", 0.0f, -45.0f);
t1.setStartDelay(500);
t1.setDuration(1500);
t1.start();

The animation works fine, also click posions are updated accordingly on ICS, but on Gingerbread click positions stays at old position which makes view un-clickable.

is there anything i can do to fix this issue on android 2.3 ?

Original Layout:

Original Layout

Trying to achieve this:

Rotated Layout

EDIT: This layout is constructed of 4 squares, each is a TextView.

1

There are 1 best solutions below

2
On

You can extend View to handle touch events yourself, and tell in which area you are clicking, depending on your value of rotation at the moment of the click.

Something like this:

public class WrapBtnSelect extends RelativeLayout {
    // Copy onstructors here

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            double x = (event.getX() / getWidth()) * 2 - 1;
            double y = (event.getY() / getHeight()) * 2 - 1;
            double angle = Math.atan2(y, x);
            // Do your actions depending on the angle here

            return true;
        }
        return super.onTouchEvent(event);
    }
}