在Android <API Level 11中旋转ImageView

seb*_*ock 6 static android rotation drawable imageview

因此,在API Level 11中,谷歌推出了旋转ImageView的能力(耶和华,他们介绍了动画这种旋转的可能性,耶和聪明思考,耶!)

但是我应该如何使用例如API级别8旋转ImageView?我不能使用如上所述的setRotation().

Ren*_*eno 7

自Api等级1起存在RotationAnimation

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 );
Run Code Online (Sandbox Code Playgroud)


seb*_*ock 2

我开始创建位图并旋转画布/矩阵,但这不是一个好的解决方案。最后,如果满足条件,则仅交换可绘制对象。我应该说这是一个 ExpandableListView,其中在绘制时重复使用单元格。

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);
    }
Run Code Online (Sandbox Code Playgroud)

我通常不是 Android 开发人员,但我真的很惊讶可以为旋转设置动画,但不能静态设置可绘制对象的旋转。从逻辑上讲,第一个是第二个的子集,而不是相反。