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

2019-07-04 16:19发布

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!

2条回答
成全新的幸福
2楼-- · 2019-07-04 16:46
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

查看更多
放我归山
3楼-- · 2019-07-04 16:49
ObjectAnimator animation = ObjectAnimator.ofFloat(view, "rotationY", 0.0f, 360f);
    animation.setDuration(3600);
    animation.setRepeatCount(ObjectAnimator.INFINITE);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());
    animation.start();
查看更多
登录 后发表回答