Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotating ImageView in Android < API Level 11

So in API Level 11 Google introduced the ability to rotate an ImageView (Yay, after they introduced the possibility to Animate such a rotation, yay smart thinking, yay!)

But how should I go about to rotate an ImageView using e.g. API level 8? I can't use setRotation() as described above.

like image 463
sebrock Avatar asked Oct 03 '11 11:10

sebrock


People also ask

How to Rotate background in Android Studio?

Rotate your image manually using whatever editor you want, and place it in the drawable-land folder. This way, when the phone is rotated to landscape, the system will pick up the resource (image) that you placed in that folder instead of the "portrait" one used in the default drawable folder.


2 Answers

RotationAnimation was present since Api level 1

RotateAnimation animation = new RotateAnimation(from, to,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setInterpolator(new LinearInterpolator());
animation.setDuration(1);
animation.setFillAfter(true);

imageView.startAnimation(animation );
like image 157
Reno Avatar answered Oct 09 '22 08:10

Reno


I started with creating BitMap and rotating the canvas/matrix, however this was not a good solution. Finally ended up just swapping the drawable if conditions are met. I should say this is an ExpandableListView where cells are reused when drawing.

if (isExpanded) {
        ImageView view = (ImageView) convertView.findViewById(R.id.ImageView);
        view.setImageResource(R.drawable.quickactions_button_normal_down);
    }

    if (!isExpanded) {
        ImageView view = (ImageView) convertView.findViewById(R.id.ImageView);          
        view.setImageResource(R.drawable.quickactions_button_normal);
    }

I'm not usually a Android developer but I'm really amazed that it is possible to animate a rotation, but not statically set the rotation of a drawable. Logically the first is a subset of the second and not the other way around.

like image 24
sebrock Avatar answered Oct 09 '22 10:10

sebrock