【问题标题】:Animation between fragments片段之间的动画
【发布时间】:2017-09-19 11:52:40
【问题描述】:

我想要片段之间的动画。 第二个片段应该从右下角滑出,第一个片段(当前片段应该保持原样)应该在点击 FAB 按钮时发生。

我尝试过的。

ft.setCustomAnimations(R.anim.slide_in_from_bottom_right,R.anim.stay);

                ft.replace(R.id.sample_content_fragment, fragment, "XYZ");
                ft.addToBackStack("XYZ");
                Bundle bundle = new Bundle();

                fragment.setArguments(bundle);
                ft.commit();

slide_in_from_bottom_right.xml:-

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="100%p" android:fromXDelta="100%p" android:toYDelta="0%p"
        android:duration="600"
        android:fillAfter="true"
        android:interpolator="@android:anim/linear_interpolator"
        />
</set>

stay.xml:-

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

问题是我看不到实际的滑入。 我在这里错过了什么?

【问题讨论】:

标签: android animation fragment


【解决方案1】:

如果你想保持第一个片段不变,那么你不需要为第一个片段定义动画资源。

ft.setCustomAnimations(R.anim.slide_in_from_bottom_right,0);

我刚刚更新了您的 slide_in_from_bottom_right.xml 以完美地翻译来自 100% x and y to 0% x and y 的视图。

slide_in_from_bottom_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate 
  android:fromYDelta="100%p" 
  android:fromXDelta="100%p" 
  android:toYDelta="0%p"
  android:toXDelta="0%p"
  android:duration="600"
  android:fillAfter="true"
  android:interpolator="@android:anim/linear_interpolator"
/>

您还可以设置第二个片段从第二个片段返回到第一个片段时的弹出动画。

ft.setCustomAnimations(R.anim.slide_in_from_bottom_right,0,0,R.anim.pop_slide_in_from_top_left.xml);

pop_slide_in_from_top_left.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="600">

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="600"
    android:fromXDelta="0%p"
    android:fromYDelta="0%p"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toXDelta="100%p"
    android:toYDelta="100%p" />
</set>

【讨论】:

    猜你喜欢
    • 2011-06-23
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-12
    相关资源
    最近更新 更多