FrameLayout中的FAB位于片段之上

Xen*_*Sis 2 android android-layout android-fragments floating-action-button android-framelayout

在我的布局中,我有一个FrameLayout我打算根据用户输入显示不同的布局.我想FloatingActionButton在所有这些布局中显示一个.

为了不重复FloatingActionButton所有这些,我想把它附加到FrameLayout.问题是按钮未在fragment布局顶部正确显示.例如,fragment显示的初始GridView值为a ,按钮位于其后面.

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="xeniasis.mymarket.MainActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:baselineAligned="false"
        android:orientation="horizontal"
        android:weightSum="4">

        <LinearLayout
            android:id="@+id/categories_layout"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:paddingRight="20dp">

            <ExpandableListView
                android:id="@+id/categories_listView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>

        <FrameLayout
            android:id="@+id/mainPane"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3">

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/settings"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|start"
                android:layout_margin="8dp"
                android:clickable="true"
                android:elevation="5dp"
                android:src="@android:drawable/ic_menu_search" />
        </FrameLayout>
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

并以fragment编程方式显示布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="xeniasis.mymarket.MainActivity">

        <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/swipeRefreshContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="8dp"
            android:paddingRight="8dp"
            android:paddingTop="@dimen/activity_vertical_margin">

            <GridView
                android:id="@+id/productsGridview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:numColumns="3"></GridView>

        </android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

结果: 在此输入图像描述

Uda*_*day 6

FrameLayout,声明另一个Framelayout并在那里膨胀片段.它应该工作.

... <LinearLayout>
     .....

   <FrameLayout
        android:id="@+id/mainPane"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3">

        <FrameLayout
            android:id="@+id/fragment_inflate"
            android:layout_width="match_parent"
            android:layout_height="match_parent">


        <android.support.design.widget.FloatingActionButton
            android:id="@+id/settings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|start"
            android:layout_margin="8dp"
            android:clickable="true"
            android:elevation="5dp"
            android:src="@android:drawable/ic_menu_search" />
    </FrameLayout>
Run Code Online (Sandbox Code Playgroud)