简体   繁体   English

如何在Android Studio中的imageView上添加具有不同轴的两个旋转?

[英]how to add two rotation with different pivots on a imageView in android studio?

I was trying to do rotations on an ImageView , each of which has its own pivot . 我试图在ImageView上进行旋转,每个旋转都有其自己的pivot One is meant to have default pivots while the other has (0, 0) as its pivots. 一个意味着具有默认枢轴,而另一个具有(0,0)作为其枢轴。 While trying to do this, only the last rotation is done on the view. 尝试执行此操作时,仅在视图上完成了最后的旋转。 How can I have them both work simultaneously? 如何让它们同时工作?

Here is my attempt: 这是我的尝试:

  this.animate().rotation(180f).setDuration(0);
  setPivotX(0);
  setPivotY(0);
  this.animate().rotation((float) Math.toDegrees(Math.atan((y2 - y1) / (x2 - x1)))).setDuration(0);

This is done inside a function of a class implementing imageView . 这是在实现imageView的类的函数内完成的。

You should use ParallelTransition, here is my example for it: 您应该使用ParallelTransition,这是我的示例:

ParallelTransition pt = new ParallelTransition();

    RotateTransition rx=new RotateTransition(Duration.seconds(5), this);
    rx.setAxis(Rotate.X_AXIS);

    RotateTransition rz=new RotateTransition(Duration.seconds(5), this);
    rz.setAxis(Rotate.Z_AXIS);

    rx.setFromAngle(0);
    rx.setToAngle(90*xrotate);

    rz.setFromAngle(0);
    rz.setToAngle(90*zrotate);

    pt.getChildren().addAll(rz,rx);

    pt.play();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM