我必须在单击按钮时旋转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);
}
}发布于 2011-09-05 20:51:17
在这条线上
rAnim = RotateAnimation(0f,degree,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimation.RELATIVE_TO_SELF,0.5f);
将0f更改为所需的起始角度。
https://stackoverflow.com/questions/7308110
复制相似问题