【问题标题】:android ObjectAnimator pivot pointsandroid ObjectAnimator 枢轴点
【发布时间】:2020-07-16 17:15:39
【问题描述】:

美好的一天。

如果可能的话,我将不胜感激。

下面的代码非常适合将 imageView 移动到 x = 200 和 y = 100。在此移动之后,ImageView 围绕中心 (0,0) 位置旋转 360 度。

如何在 X = 200 和 Y = 100 时设置 pivotX 和 pivotY 值?

提前谢谢你。

保罗

public void onButtonClickRotate(View v) {

    ObjectAnimator animatorX = ObjectAnimator.ofFloat(imageView, "translationX",  200f);

    ObjectAnimator animatorY = ObjectAnimator.ofFloat(imageView, "translationY",  100f)
                .setDuration(100);

    ObjectAnimator rotation = ObjectAnimator.ofFloat(imageView,"rotation",  0f, 360f)
                .setDuration(1000);

    AnimatorSet set = new AnimatorSet();


    set.playSequentially(animatorX, animatorY,rotation);
        set.setDuration(2000);
        set.start();
    }
}

【问题讨论】:

    标签: android imageview


    【解决方案1】:

    要在枢轴点上旋转,请使用以下内容:

    val imageView = view.findViewById<ImageView>(R.id.imageView)
    val pivotY = ObjectAnimator.ofFloat(imageView, "pivotX", 30f)
    val pivotX = ObjectAnimator.ofFloat(imageView, "pivotY", 70F)
    val animR = ObjectAnimator.ofFloat(imageView, "rotation", 0F, 360F)
    AnimatorSet().apply {
        playTogether(animX, animY, animR)
        start()
    }
    
    

    只需设置所需的枢轴值。请务必在此处查看有关属性动画的指南以获取更多详细信息和其他(也许更好的)方法:https://developer.android.com/guide/topics/graphics/prop-animation

    【讨论】:

      【解决方案2】:

      在我的用例中,以下工作:

      // set pivot point of the object
      imageView.pivotX = pX
      imageView.pivotY = pY
      
      // start rotation animation. e.g. Y axes
      oaY = ObjectAnimator.ofFloat(
                  imageView,
                  "rotationY",
                  0f, 360f, 0f)
      oaY.start()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-06-06
        • 2018-11-01
        • 2018-03-05
        • 1970-01-01
        • 1970-01-01
        • 2016-09-07
        • 2016-06-07
        相关资源
        最近更新 更多