Android CoordinatorLayout和嵌套片段问题

时间:2017-06-11 07:55:28

标签: android android-fragments material-design android-coordinatorlayout

我是这种布局的主要活动:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/toolbar_container">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:fitsSystemWindows="true"
        android:elevation="0dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:titleEnabled="false"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

                <ImageView
                    android:layout_gravity="center"
                    app:srcCompat="@drawable/ic_logo_toolbar"
                    android:layout_width="100dp"
                    android:layout_height="?attr/actionBarSize" />

            </android.support.v7.widget.Toolbar>

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/myScrollingContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:fillViewport="true">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <RelativeLayout
                android:id="@+id/container_RL"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </FrameLayout>

    </android.support.v4.widget.NestedScrollView>

    <com.roughike.bottombar.BottomBar
        android:id="@+id/bottom_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/bottom_bar_height"
        android:layout_gravity="bottom"
        android:background="@color/white"
        app:bb_activeTabColor="@color/colorPrimary"
        app:bb_behavior="shifting|shy"
        app:bb_inActiveTabColor="@color/black_54"
        app:bb_tabXmlResource="@xml/bottom_bar" />
</android.support.design.widget.CoordinatorLayout>

我将container_RL替换为:

detailsFragment = DetailsFragment.newInstance(storeId);
getSupportFragmentManager().beginTransaction().replace(R.id.container_RL, detailsFragment).commit();

现在工作正常。工具栏和底栏随滚动行为正确移动。 但是如果我在片段中添加一个FloatingActionMenu:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/inner_container_RL"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/windowBackground">

        <in.srain.cube.views.GridViewWithHeaderAndFooter
            android:id="@+id/gridView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:numColumns="2"
            android:orientation="horizontal" />

    </RelativeLayout>

    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/menu_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:elevation="4dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        app:layout_behavior="com.test.MoveUpwardBehaviour"
        app:layout_anchor="@id/gridView"
        app:layout_anchorGravity="bottom|right|end"
        app:menu_colorNormal="@color/colorPrimary"
        app:menu_colorPressed="#2272CD"
        app:menu_colorRipple="#62B2FF">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/fab1_item"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fab_label="F<b1"
            android:tint="@color/white"
            android:src="@drawable/ic_fab1"
            style="@style/MenuButtonsSmall" />

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/fab2_item"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:tint="@color/white"
            app:fab_label="Fab2"
            android:src="@drawable/ic_fab2"
            style="@style/MenuButtonsSmall" />
    </com.github.clans.fab.FloatingActionMenu>
</android.support.design.widget.CoordinatorLayout>

FABMenu隐藏在底栏后面。我想将FABMenu移动到底栏上方,然后当底栏移动时滚动FABMenu向下滚动。

但是FABMenu是片段的孩子,我该如何处理这种行为?

0 个答案:

没有答案