Skip to content Skip to sidebar Skip to footer

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 sh

Solution 1:

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 );

Solution 2:

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) {
        ImageViewview= (ImageView) convertView.findViewById(R.id.ImageView);
        view.setImageResource(R.drawable.quickactions_button_normal_down);
    }

    if (!isExpanded) {
        ImageViewview= (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.

Post a Comment for "Rotating Imageview In Android < Api Level 11"