【发布时间】:2016-06-16 08:25:11
【问题描述】:
我想在 Android 上以缓慢的方式旋转图像。 我可以通过创建一个位图并通过 Matrix 类的帮助。但我不知道如何让它变慢,比如旋转应该需要 3 秒。
【问题讨论】:
-
您的问题不清楚。通过旋转你的意思是动画或图像倾斜
标签: android matrix bitmap rotation
我想在 Android 上以缓慢的方式旋转图像。 我可以通过创建一个位图并通过 Matrix 类的帮助。但我不知道如何让它变慢,比如旋转应该需要 3 秒。
【问题讨论】:
标签: android matrix bitmap rotation
旋转
旋转动画使用标签。对于旋转动画,需要的标签是 android:fromDegrees 和 android:toDegrees,它们定义了旋转角度。
顺时针 - 使用正 toDegrees 值
逆时针方向 - 使用负 toDegrees 值
旋转.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="600"
android:repeatMode="restart"
android:repeatCount="infinite"
android:interpolator="@android:anim/cycle_interpolator"/>
</set>
保存在动画文件夹中
public class AnimationActivity extends Activity{
ImageView img;
Animation rotate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fadein);
img = (ImageView) findViewById(R.id.myimageid);
// load the animation
rotate = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.rotate);
img.startAnimation(rotate);
}
}
【讨论】:
在 Kotlin 中,您可以使用 ObjectAnimator 超级轻松地做到这一点。例如:
ObjectAnimator.ofFloat(view, "rotationX", 180f).apply {
duration = 2000
start()
}
【讨论】:
您可以使用旋转动画来实现这一点。
在该 xml 所在的 res 目录下创建 anim 文件夹。
rotate_around_center_point.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<rotate
android:duration="2500"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
</set>
将动画设置为这样查看。
ImageView animationTarget = (ImageView) this.findViewById(R.id.testImage);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_around_center_point);
animationTarget.startAnimation(animation);
【讨论】: