翻转动画

时间:2017-11-09 14:13:17

标签: android android-animation android-cardview flip objectanimator

我试图在Android中制作翻转动画。 我正在使用此代码:

<set xmlns:android="http://schemas.android.com/apk/res/android">
  <!-- Set alpha to 0 before animation -->
  <objectAnimator
    android:valueFrom="1.0"
    android:valueTo="0.0"
    android:propertyName="alpha"
    android:duration="0"/>

  <!-- Rotate -->
  <objectAnimator
    android:valueFrom="180"
    android:valueTo="0"
    android:propertyName="rotationY"
    android:interpolator="@android:interpolator/accelerate_decelerate"
    android:duration="@integer/card_flip_time_full"/>

  <!-- Half-way through the rotation set the alpha to 1 -->
  <objectAnimator
    android:valueFrom="0.0"
    android:valueTo="1.0"
    android:propertyName="alpha"
    android:startOffset="@integer/card_flip_time_half"
    android:duration="1"/>
</set>

但是,我希望它从上到下翻转。像这样:

Flip

我该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以通过编程方式执行此操作。这是Xamarin的C#。现在无法测试Java,但它将非常相似。

ImageView block = FindViewById<ImageView>(Resource.Id.imgBlock);
ObjectAnimator blockSpin = ObjectAnimator.OfFloat(block, "rotationX", 0, 360);
imageCard.PivotX = 0.5f; //so it spins on center

float scale = metrics.Density;
imageCard.SetCameraDistance(8000*scale);
  /*Set camera distance as required to avoid distortion. 
     Multiplying by scale keeps distance the same across devices. */
blockSpin.SetDuration(500);
blockSpin.Start();