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.
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.
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 );
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With