【问题标题】:Image starts rotating from starting position after one click单击后图像从起始位置开始旋转
【发布时间】:2017-07-04 17:24:57
【问题描述】:

我有一张旋转 36° 的图像。 我使用了 setFillAfter() 和 setFillEnabled()。它正在保存位置,但如果我再次旋转它,它会从原始位置开始。我希望它从旋转后的位置开始。

Animation animation = new Animation (0,36, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(3000);
animation.setInterpolator(new LinearInterpolator());
animation.setFillAfter(true);

myImage.startAnimation(animation);

【问题讨论】:

    标签: android android-animation android-imageview android-image


    【解决方案1】:

    您只需在 Animation 构造函数中传递当前的 imageview 角度,而不是每次都传递 0。试试下面的代码:

            int rotationAngle=36;/*angle by which you want to rotate image*/
            int mCurrRotation = 0;  /*current angle of image*/
    
            buttonRotate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                float fromRotation = mCurrRotation;
                float toRotation = mCurrRotation += rotationAngle;
    
                Animation animation = new RotateAnimation(
                        fromRotation,
                        toRotation,
                        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    
    
                animation.setDuration(3000);
                animation.setFillAfter(true);
                myImage.startAnimation(animation);
            }
        });
    

    【讨论】:

      【解决方案2】:

      为此,在执行旋转后,将图像的 x y 坐标设置为旋转的新位置...

      【讨论】:

        猜你喜欢
        • 2021-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-08
        相关资源
        最近更新 更多