【问题标题】:Transition between Activity and fragmentActivity 和 Fragment 之间的过渡
【发布时间】:2017-12-26 12:59:01
【问题描述】:

我想在单击按钮时从 Activity 重定向到 Fragment 时进行转换。 我在单击活动中的按钮时使用下面的代码,但在从 Activity 重定向到 Fragment 时无法显示转换,但相同的代码在 Fragment 到 Fragment 的重定向之间工作正常。

 FragmentTransaction ft = act.getSupportFragmentManager().beginTransaction();
               ft.setCustomAnimations(R.anim.slide_from_bottom,
                       R.anim.slide_to_top,
                       R.anim.slide_from_top,
                       R.anim.slide_to_bottom);
               ft.add(R.id.framContainer, new 
AddMealFragment()).addToBackStack(null).commit();

slide_from_bottom.xml

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

slide_to_top.xml

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

slide_from_top.xml

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

slide_to_bottom.xml

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

【问题讨论】:

    标签: android xml android-fragments transition


    【解决方案1】:

    Activity 到 Fragment 之间的过渡动​​画

    它决定了共享元素视图如何从一个动画 在场景转换期间将 Activity/Fragment 转移到另一个。

    该项目解释了在 Android 中如何从一个 Activity 转换到另一个 Activity。并通过单击列表项进行动画,结果显示另一个活动中各个项目的详细信息。当从一个活动过渡到另一个活动时,我们可以轻松地在两个屏幕之间绘制图片。在详细屏幕中,我们显示下一个连续的列表项,并通过单击相应的列表项显示相应项的详细信息,然后是动画。

    查看以下 Github 链接:

    Transition Animation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多