片段及以上的动画幻灯片 [英] Fragments and slide over animation

查看:127
本文介绍了片段及以上的动画幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

花了相当多的时间寻找在此之后,我需要在这里请求帮助。

After having spent quite a bit of time searching for this, I need to request help here.

我有一系列的片段中的每个RE presenting一页。
我想给用户打算,他已要求在下一个页面时一个漂亮的动画效果。

I have a series of fragments each representing a "page". I want to give the user a nice animation effect when going to the next page he has requested.

我想,在超过previous片段新片段的幻灯片,隐藏它,就好像它是一个坚实的页面。
在present我可以在新的片段下滑,但我们仍然可以看到在过渡期间的基本片段。

I want that the new fragment slides in over the previous fragment, hiding it as if it were a solid page. At present I can slide in the new fragment, but we can still see the underlying fragment during the transition.

下面是我的幻灯片过渡的定义:

Here is my "slide in" transition definition :

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <objectAnimator
        android:duration="500"
        android:propertyName="x"
        android:valueFrom="-1280"
        android:valueTo="0"
        android:valueType="floatType" />
</set>

这是我的淡出过渡

And here is my fade out transition

<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <objectAnimator
        android:propertyName="alpha"
        android:duration="500"
        android:valueFrom="1.0"
        android:valueTo="0"
        android:valueType="floatType" />
</set>

我申请它:

Fragment f = (Fragment)FragClass.newInstance();
FragmentTransactionft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(R.animator.fragment_slide_in, R.animator.fragment_fade_out);
ft.replace(R.id.fl_frame, f);
ft.commit();

我看到了我想用的 ViewPager - 但我使用的片段。
可这种转变(只是从末所示的左位移动)与动画片段可以实现?
或者片段动画和属性动画的组合? - 试过,但它得到了非常混乱

I have seen the kind of effect I want being demonstrated with the ViewPager - but I am using Fragments. Can this kind of transition (just the moving in from the left bit shown at the end) be achieved with fragment animation ? Or perhaps a mix of fragment animation and property animation ? - tried this but it got very messy.

我建立于Android 4.0及以上平板电脑。

I am building for Android 4.0 and above on tablets.

我不希望使用ViewPager对于这一点,试图避免的支持库。

I do not want to use the ViewPager for this, trying to avoid the support library.

推荐答案

相当多的实验和测试后,这里是我采用的方法。

After quite a bit of experimentation and testing, here is the method I adopted.

可能不是最好的,但它为我工作。

Probably not the best, but it works for me.


  1. 创建的片段的动画这无助

  2. 当创建新的片段,通过在初始X位置,它是容器视图的负宽度。这将使新的碎片偏移到容器视图并为此隐蔽,左侧现在。

  3. 在FragmentTransaction呼叫setCustomAnimations与留还是动画

  4. 使用FragmentTransaction 添加新片段

  5. 创建一个动画监听器,在onAnimationEnd,将调用包含在视图做到以下几点。

  6. 通过调用bringChildToFront交换的两种观点的顺序

  7. 在旧观点开始新的视图动画缩水和褪色它

  8. 开始在新视图新视图动画,它滑动

  9. 附加的AnimatorListener到动画让老视图可以在动画结束时被删除。

这是需要遵循的步骤,剩下的只是执行:-D

These are the steps to follow, the rest is just implementation :-D

这篇关于片段及以上的动画幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆