【问题标题】:Flip Up Animation翻转动画
【发布时间】:2018-04-22 13:48:55
【问题描述】:

我正在尝试在 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>

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

我该怎么做?

【问题讨论】:

  • 尝试将 propertyName 从 android:propertyName="rotationY" 更改为 android:propertyName="rotationX"
  • @InnocentKithinji 试过了。没用。
  • 这是 2D 还是 3D 动画? 2D 动画需要一系列预渲染帧 (FrameAnimation)。 3D 动画需要实时渲染对象(OpenGL、Rajawaly 或其他)。
  • @BernoulliGate 2D 动画。我想让视图旋转以使其看起来像在翻转
  • @BernoulliGate 好的。也许我会留在侧空翻...... :)。谢谢。

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


【解决方案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();

【讨论】:

  • 哇,太好了!虽然它不能完全解决我的问题,因为我希望在翻转对象的另一侧会有另一个视图,或者至少是一个白色背景。这只是在另一侧显示刚刚旋转的相同视图。任何想法如何完善这个?
  • 嗯,我将旋转设置为 90 度,看起来效果不错;另一面是不可见的,在动画结束时,我揭示了“下面”的内容。谢谢!!
猜你喜欢
  • 1970-01-01
  • 2011-03-22
  • 2019-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多