【问题标题】:Android: How to make the flip animation for android activity, as like iphone flip horizontal from left to right?Android:如何为 android 活动制作翻转动画,就像 iphone 从左到右水平翻转一样?
【发布时间】:2012-01-19 22:47:00
【问题描述】:

在我的应用程序中,我想翻转视图.. 我在 iPhone 中看到过这样的动画。和我想要在我的 android 应用程序中一样的东西。

我想翻转整个活动视图。可能吗 ? 我在android中看到了一些翻转的例子。但在所有示例中,视图都在同一个活动中。是否可以为不同的活动设置这样的视图。还是在从一项活动转到另一项活动时产生这种效果?

请查看 iPhone 中翻转效果的快照:

如果是,请参考任何演示示例或代码。 谢谢。

【问题讨论】:

  • 分别寻找 android.R.anim。 sdk 版本文件夹你可以找到一些例子。

标签: android android-layout android-widget android-animation flip


【解决方案1】:

首先定义您自己的动画,然后将其存储在 res->anim 或 java 类下的 XML 中。除了 Eclipse 中的 SDK 下载附带的 API Demos 之外,我没有任何工作示例,如果您正在寻找翻转动画,请尝试查看 3D Transition 类。

之后让您的 Activity 加载该动画,最好在 onCreate 中加载它。请参考这个question

【讨论】:

    【解决方案2】:

    我见过的最令人信服的 Android 3D 翻转动画之一是在这里完成的 https://code.google.com/p/android-3d-flip-view-transition

    许多其他教程和示例代码无法生成可信的 3D 翻转。 y 轴上的简单旋转不是 iOS 中所做的。

    这里还有一个视频:http://youtu.be/52mXHqX9f3Y

    【讨论】:

      【解决方案3】:

      您可以使用这些 xml 文件制作非常相似的文件。

      rotate_out.xml

      <?xml version="1.0" encoding="utf-8"?>
      

      <scale
          android:duration="300"
          android:fromXScale="1.0"
          android:fromYScale="1.0"
          android:interpolator="@android:anim/accelerate_decelerate_interpolator"
          android:pivotX="50%"
          android:pivotY="50%"
          android:toXScale="0.0"
          android:toYScale="0.90" />
      
      <alpha
          android:duration="1"
          android:fromAlpha="1.0"
          android:startOffset="500"
          android:toAlpha="0.0" />
      

      rotate_in.xml

      <?xml version="1.0" encoding="utf-8"?>
      

      <scale
          android:duration="200"
          android:fromXScale="0.0"
          android:fromYScale="0.90"
          android:interpolator="@android:anim/accelerate_decelerate_interpolator"
          android:pivotX="50%"
          android:pivotY="50%"
          android:startOffset="500"
          android:toXScale="1.0"
          android:toYScale="1.0" />
      
      <alpha
          android:duration="1"
          android:fromAlpha="0.0"
          android:startOffset="500"
          android:toAlpha="1.0" />
      

      然后在你的代码中覆盖 startActivity() 或 finish() 之后的转换:

      overridePendingTransition(R.anim.rotate_in, R.anim.rotate_out);
      

      【讨论】:

      • 这是旋转,不是翻转
      • @Boy,可能是比例尺,不是旋转,但看起来像翻转。
      • 多个根标签
      【解决方案4】:

      在 iOS 纵向:

      “许多其他教程和示例代码都无法生成可信的 3D 翻转。在 y 轴上的简单旋转不是 iOS 中所做的。” 在寻找样品将近 30 小时后,我不得不同意。 我有一部电影,我可以在中间截屏。 视图的右侧有: - 向左移动并缩小到 95%。 视图的左侧有: - 向右移动并缩小到 80%。

      在 Android Full(初始状态):

      Android 中:

      安卓代码:

      // @param interpolatedTime The value of the normalized time (0.0 to 1.0)
      // @param t The Transformation object to fill in with the current transforms.
      protected void applyTransformation(float interpolatedTime, Transformation t){
      
          float degrees = toDegree*interpolatedTime;
          //float rad = (float) (degrees * Math.PI / 180.0f);
      
          Matrix matrix = t.getMatrix();
          camera.save();
      
          camera.rotateY(degrees);
          camera.getMatrix(matrix);
          camera.restore();
      
          matrix.preTranslate(-centerX, -centerY);// M' = M * T(dx, dy)
          matrix.postTranslate(centerX, centerY); // M' = T(dx, dy) * M
      }
      

      代码的改进版本可以在大多数示例中找到:

          // @param interpolatedTime The value of the normalized time (0.0 to 1.0)
          // @param t The Transformation object to fill in with the current transforms.
          protected void applyTransformation(float interpolatedTime, Transformation t){
      
              float degrees = toDegree*interpolatedTime;
              //float rad = (float) (degrees * Math.PI / 180.0f);
      
              Matrix matrix = t.getMatrix();
              camera.save();
      
              camera.translate(0.0f, 0.0f, mDepthZ *  interpolatedTime);
              camera.rotateY(degrees);
      
              camera.getMatrix(matrix);
              camera.restore();
      
              matrix.preTranslate(-centerX, -centerY);// M' = M * T(dx, dy)
              matrix.postTranslate(centerX, centerY); // M' = T(dx, dy) * M
          }
      

      一些区别是: - 视图的右侧不会像 iOS 那样移动。

      这是 Android 相机轴:

      我确实相信 Z 轴上的平移无法解决此问题。也许也需要收缩。

      float dz = (float) (centerX *  Math.sin(rad));
      camera.translate(0f, 0f, -dz);
      

      还是不够。左侧缩小太多了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-03-22
        • 2014-06-06
        • 2020-04-28
        • 1970-01-01
        • 2017-07-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多