Sameer Segal Sameer Segal - 3 months ago 21
Android Question

Drawable Rotating around its center Android

I am getting strange results with the following code:

iv = (ImageView) findViewById(R.id.iv);
iv.setImageResource(R.drawable.spinner_white_76);

Animation a = new RotateAnimation(0.0f, 360.0f,
Animation.RELATIVE_TO_SELF, iv.getDrawable()
.getIntrinsicWidth() / 2, Animation.RELATIVE_TO_SELF,
iv.getDrawable().getIntrinsicHeight() / 2);
a.setRepeatCount(-1);
a.setDuration(1000);

iv.startAnimation(a);


Whats the right way to specify the axis point (center of the drawable)?

Answer

Feel stupid! Got it to work after spending some time closely reading the documentation:

Animation a = new RotateAnimation(0.0f, 360.0f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        a.setRepeatCount(-1);
        a.setDuration(1000);
Comments