Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在安卓图标的中心点旋转?_Android_Animation_Rotation - Fatal编程技术网

Android 如何在安卓图标的中心点旋转?

Android 如何在安卓图标的中心点旋转?,android,animation,rotation,Android,Animation,Rotation,我写了以下内容来旋转屏幕中央的图标,而不是围绕左上角旋转(即ImageView的原点x=0,y=0)。设置ImageView或RotateAnimation的一些属性应该很简单,但我无法理解 public class IconPromoActivity extends Activity { private static final float ROTATE_FROM = 0.0f; private static final float ROTATE_TO = -10.0f * 3

我写了以下内容来旋转屏幕中央的图标,而不是围绕左上角旋转(即ImageView的原点x=0,y=0)。设置ImageView或RotateAnimation的一些属性应该很简单,但我无法理解

public class IconPromoActivity extends Activity {
    private static final float ROTATE_FROM = 0.0f;
    private static final float ROTATE_TO = -10.0f * 360.0f;// 3.141592654f * 32.0f;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ImageView favicon = (ImageView) findViewById(R.id.favicon);

        RotateAnimation r; // = new RotateAnimation(ROTATE_FROM, ROTATE_TO);
        r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, 0, 0, 40, 0);
        r.setDuration((long) 2*1500);
        r.setRepeatCount(0);
        favicon.startAnimation(r);
    }
}
尝试:
r=新的旋转动画(旋转自、旋转至、动画.相对自、0.5f、动画.相对自、0.5f)

这对我很有用:

img = (ImageView)findViewById(R.id.ImageView01);
RotateAnimation rotateAnimation = new RotateAnimation(30, 90,
    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

下面是完整的例子

public class MainActivity extends AppCompatActivity implements MainActivityMvpModel {
    ImageView imageViewThumb;

    private static final float ROTATE_FROM = 30.0f;
    private static final float ROTATE_TO = 360.0f;
    RotateAnimation r; // = new RotateAnimation(ROTATE_FROM, ROTATE_TO);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        buttonTest= (Button) findViewById(R.id.button_test);

        imageViewThumb= (ImageView) findViewById(R.id.icon_thumb);
        imageViewThumb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                r.setDuration((long) 2*500);
                r.setRepeatCount(0);
                imageViewThumb.startAnimation(r);

                imageViewThumb.setColorFilter(R.color.colorThumbPressed);
            }
        });
    }
}

如何将其添加到图像中,使其连续旋转,直到您告诉它停止为止。
rotationAnimation.setDuration(Animation.INFINITE)当您想要停止动画时:
ImageView myRotatingImage=(ImageView)mRoot.findViewById(R.id.my\u rotating\u image)
myRotatingImage.clearAnimation()无效:java.lang.IllegalArgumentException:动画持续时间不能为负您可以使用-rotateAnimation.setRepeatCount(Animation.INFINITE);你能解释一下吗。因此,我们可以根据需要轻松地进行修改。这就是我正在寻找的。我将其修改为将_从=0.0f旋转到=45.0f;这将再次恢复到原始方向