【问题标题】:3d flip animation inside a fragment片段内的 3d 翻转动画
【发布时间】:2016-02-10 01:57:31
【问题描述】:

我想在片段内的两个图像视图上实现 3d 翻转动画。 我有两张人体图像,即正面和背面。我想要的是当用户单击按钮时将前面的图像翻转到后面。所有这些都在一个标签片段中。

我搜索这个超过 1 小时,但没有得到任何有用的东西。 我得到了一些与 hoe 相关的结果,以实现其中包含片段的 3d 翻转动画,但没有得到任何与我想要的相关的结果。

谁能帮我解决这个问题?

谢谢

【问题讨论】:

    标签: android image animation android-fragments flip


    【解决方案1】:

    使用ObjectAnimator,“翻转”动画相当简单。一个示例实现可能是:

    ObjectAnimator animator = ObjectAnimator.ofFloat(mImageView, "rotationY", 0F, 360F);
    animator.setDuration(1000);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.start();
    

    这应该会翻转您的 ImageView 并为您提供开始的地方。

    编辑:您或许可以将第一个ImageView 翻转为180F(这样它实际上变得不可见),然后使用AnimatorListener 在第二个ImageView 上开始另一个翻转,同样来自180F,因此看起来一张图片已转换为另一张图片。

    【讨论】:

    • 是否可以在片段中实现它?你能帮我一些教程吗?这样我就很容易理解和实现它
    • @Arpita “在片段内”是什么意思?在Fragment 内部的ImageView 上使用ObjectAnimatorActivity 内部应该没有什么不同?
    • 这就像我用导航抽屉实现了滑动标签。我想在其中一个滑动标签片段内的图像之间添加 3d 翻转动画。
    【解决方案2】:

    我认为你看起来像这样。

     image1 = (ImageView) findViewById(R.id.ImageView01);
     image2 = (ImageView) findViewById(R.id.ImageView02);
     image2.setVisibility(View.GONE);
    
    
    
    image1.setOnClickListener(new View.OnClickListener() {
      public void onClick(View view) {
      if (isFirstImage) {       
      applyRotation(0, 90);
      isFirstImage = !isFirstImage;
    
      } else {    
      applyRotation(0, -90);
     isFirstImage = !isFirstImage;
     }
     }
    });      
    
    
    
    
    private void applyRotation(float start, float end) {
    // Find the center of image
    final float centerX = image1.getWidth() / 2.0f;
    final float centerY = image1.getHeight() / 2.0f;
    
    // Create a new 3D rotation with the supplied parameter
    // The animation listener is used to trigger the next animation
    final Flip3dAnimation rotation =
       new Flip3dAnimation(start, end, centerX, centerY);
    rotation.setDuration(500);
    rotation.setFillAfter(true);
    rotation.setInterpolator(new AccelerateInterpolator());
    rotation.setAnimationListener(new DisplayNextView(isFirstImage,    image1,   image2));
    
    if (isFirstImage)
    {
    image1.startAnimation(rotation);
    } else {
    image2.startAnimation(rotation);
    }
    
    }
    

    您可以从这里找到完整的源代码 http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html

    希望对你有帮助。祝你好运

    【讨论】:

    • 太棒了。它也帮助了我。谢谢
    猜你喜欢
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 2016-12-27
    • 2014-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多