0

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.

Nevercom
  • 840
  • 3
  • 14
  • 38

1 Answers1

1

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);
    }
}
minipif
  • 4,756
  • 3
  • 30
  • 39
  • This layout is constructed of 4 squares, each is a `TextView`. this method seems to be somehow overwork. is it possible to actually rotate buttons ? – Nevercom Jan 27 '14 at 10:26
  • 1
    You can call `View.setRotation()` on your `RelativeLayout` but it's only available from API 11 (BTW you're also using `ObjectAnimator` which is only available from API 11). To work from API 8 I would animate the `RelativeLayout` with a View Animation, and use the custom class to handle click events, because View Animation doesn't actually move the view, so your position won't update depending on the animation. – minipif Jan 27 '14 at 10:39