How can I rotate a View by Y-axis in android?

2019-07-04 16:41发布

问题:

In my app, i would like rotate an ImageView by setRotationY(). In fact, it does. Just like from b to d, mirror effect and when i use setRotation(45) before setRotationY(), the result is that setRotationY is according to the device Y-axis, and i want the rotationY according to view self.

How? Can you guide me? Thanks!

回答1:

ObjectAnimator animation = ObjectAnimator.ofFloat(view, "rotationY", 0.0f, 360f);
    animation.setDuration(3600);
    animation.setRepeatCount(ObjectAnimator.INFINITE);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());
    animation.start();


回答2:

RotateAnimation rotate = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(5000);
rotate.setInterpolator(new LinearInterpolator());

ImageView image= (ImageView) findViewById(R.id.imageView);

image.startAnimation(rotate);

Obviously, you could just put your imageView there