我必须在单击按钮时旋转 ImageView。在第一次单击时,它必须向右旋转,第二次向左旋转等等。
问题是,当我尝试第二次旋转“刚刚旋转”的图像时,旋转从原始点开始,而不是从“第一次旋转后”点开始。
我需要旋转先前旋转产生的图像。下面我过去了代码。
public class Rotate extends Activity {
boolean mDirRight = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rotate);
final ImageView imageArray = (ImageView) findViewById(R.id.ImageViewArray);
imageArray.setImageResource(R.drawable.array01);
imageArray.setAdjustViewBounds(true);
final Button btnRotate = (Button) findViewById (R.id.ButtonRotate);
btnRotate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
doRotation();
}
});
}
private void doRotation(){
final int rotationRight = 30;
final int rotationLeft = -20;
final RotateAnimation rAnim;
int degree;
if (mDirRight) {
degree = rotationRight;
mDirRight = false;
} else {
degree = rotationLeft;
mDirRight = true;
}
final ImageView image = (ImageView) findViewById(R.id.ImageViewArray);
rAnim = new RotateAnimation(0f, degree, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rAnim.setStartOffset(0);
rAnim.setDuration(2000);
rAnim.setFillAfter(true);
rAnim.setFillEnabled(true);
image.startAnimation(rAnim);
}
}