因此,在API Level 11中,Google引入了旋转ImageView的功能(耶,他们还引入了动画旋转的可能性,聪明的想法,耶!)
但是,如果我要在API level 8上旋转一个ImageView,该怎么做呢?我不能像上面描述的那样使用setRotation()。
RotationAnimation自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 );
我最初尝试创建位图并旋转画布/矩阵,但这不是一个好的解决方案。最终只是在符合条件时交换可绘制对象。需要说明的是,这是一个可扩展列表视图,在绘制时会重复使用单元格。
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);
}
我通常不是一名Android开发人员,但我非常惊讶地发现可以对旋转进行动画处理,但无法静态设置可绘制对象的旋转。从逻辑上讲,前者是后者的子集,而不是反过来。