Rotating ImageView in Android < API Level 11

左心房为你撑大大i 提交于 2019-12-18 08:24:26

问题


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.


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



回答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) {
        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.



来源:https://stackoverflow.com/questions/7634540/rotating-imageview-in-android-api-level-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!