【发布时间】:2012-08-10 08:40:08
【问题描述】:
我有一个 ImageView 图像。我需要将此图像向右旋转 90 度,然后将其从左向右移动。我设法做到了。我使用 AnimationListener 并在旋转完成后启动 moveAnimation()。但是在运动图像恢复到原来的样子之前(旋转之前)。
用于旋转的xml代码rotation.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:toDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:startOffset="0"
/>
旋转动画()
private void rotateAnimation(){
Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);
rotation.setRepeatCount(0);
rotation.setFillAfter(true);
rotation.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation) {
moveAnnimation();
}
});
moveAnimation()
private void moveAnnimation(){
TranslateAnimation moveLefttoRight = new TranslateAnimation(0, 2000, 0, 0);
moveLefttoRight.setDuration(1000);
moveLefttoRight.setFillAfter(true);
moveLefttoRight.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
});
image.startAnimation(moveLefttoRight);
}
【问题讨论】:
-
您能否提供用于旋转和移动图像的示例代码。
-
好的,但是我给你我的意见.. 尝试使用矩阵进行旋转和类似的矩阵进行平移,这样你的矩阵将被集中并且图像视图不会被重置。在执行任何矩阵运算之前,不要忘记将 imageview 的属性 scaletype 设置为矩阵。
标签: android animation image-rotation