Android-如何使用getChildFragmentManager使用工具栏制作片段过渡动画

时间:2018-09-05 08:15:31

标签: android android-fragments fragmentmanager child-fragment

我尝试实现导航器对象。它有自己的堆栈。

我的活动布局层次结构如下:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

我的片段层次结构在这里:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragmentRootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:elevation="4dp"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimary" />

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/toolbar"
    android:id="@+id/fragmentContentLayout">
</FrameLayout>

要用动画替换fragmentA和fragmentB,当我使用activity的getSupportFragmentManager时,工具栏将动画化。

但这不符合我的要求。因为我希望每个导航器都有不同的堆栈。因此,我将以下代码与动画一起使用(从右到左)

getChildFragmentManager().beginTransaction().replace(R.id.fragmentRootLayout, fragment);

但是工具栏不会从右向左滑动。

0 个答案:

没有答案