首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android RotateAnimation,如何进行更多的旋转?

Android RotateAnimation,如何进行更多的旋转?
EN

Stack Overflow用户
提问于 2011-09-05 20:30:55
回答 1查看 4.1K关注 0票数 1

我必须在单击按钮时旋转ImageView。在第一次单击时,它必须向右旋转,在第二次单击时向左旋转,等等。

问题是,当我试图第二次旋转“刚刚旋转”的图像时,旋转是从原始点开始的,而不是从“第一次旋转后”点开始。

我需要旋转之前旋转产生的图像。下面我将跳过代码。

代码语言:javascript
复制
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);
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-05 20:51:17

在这条线上

rAnim = RotateAnimation(0f,degree,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimation.RELATIVE_TO_SELF,0.5f);

将0f更改为所需的起始角度。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7308110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档