如何在android中按Y轴旋转View?

问题描述 投票:0回答:3

在我的应用程序中,我想将

ImageView
旋转
setRotationY()
。事实上,确实如此。就像从b到d一样,镜像效果,当我在
setRotation(45)
之前使用
setRotationY()
时,结果是
setRotationY
是根据设备
Y-axis
,而我想要根据自我视图的
rotationY

如何?你能指导我吗? 谢谢!

android animation view rotation
3个回答
22
投票
ObjectAnimator animation = ObjectAnimator.ofFloat(view, "rotationY", 0.0f, 360f);
    animation.setDuration(3600);
    animation.setRepeatCount(ObjectAnimator.INFINITE);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());
    animation.start();

0
投票

似乎这是获得类似结果的唯一方法:

  • handler1 执行无限循环。

  • scaleDownX.setDuration(1500); 创建图像沿中轴旋转 180 度的错觉,持续时间为 1500ms

  • scaleDownX2.setDuration(1500); 创建图像沿中轴随后旋转 180 度的错觉,持续时间为 1500ms

    ImageView golden1 = (ImageView) findViewById(R.id.golden1);
    
    final Handler handler1 = new Handler();
         handler1.postDelayed(new Runnable() {
             @Override
             public void run() {
                 ObjectAnimator scaleDownX = ObjectAnimator.ofFloat(golden1, "scaleX", 0, -1f);
                 scaleDownX.setDuration(1500);
                 scaleDownX.start();
    
                 final Handler handler2 = new Handler();
                 handler2.postDelayed(new Runnable() {
                     @Override
                     public void run() {
                         ObjectAnimator scaleDownX2 = ObjectAnimator.ofFloat(golden1, "scaleX", -1f, 0);
                         scaleDownX2.setDuration(1500);
                         scaleDownX2.start();
                     }
                 }, 1500);
                 handler1.postDelayed(this, 3000);
             }
         }, 100);
    

-1
投票
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);

显然,你可以把你的 imageView 放在那里

© www.soinside.com 2019 - 2024. All rights reserved.