RotateDrawable表示将一个Drawable资源,以平面旋转多少度的后的形式(基于level)。
RotateDrawable的属相介绍:(res/drawable/rotate.xml)
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:visible="true" //是否可见
android:fromDegrees="0" //从多少度开始选装
android:toDegrees="90" //到多少度结束,其实随着level的增加,图片可以一直旋转
android:pivotX="50%" //旋转中心的x坐标
android:pivotY="50%" //选装中心的y坐标
android:drawable="@drawable/aa"> //指定drawable资源文件
</rotate>
引用:
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:src="@drawable/rotate"/>
让Drawable资源图片,每点击一下顺时针旋转。
ImageView iv=(ImageView) findViewById(R.id.iv);
final RotateDrawable rotateDrawable=(RotateDrawable) iv.getDrawable();
rotateDrawable.setLevel(1);
iv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
rotateDrawable.setLevel(rotateDrawable.getLevel()+1000);
}
});