如何将CoordinatorLayout放入RelativeLayout中?

时间:2019-03-14 17:27:14

标签: android android-coordinatorlayout android-relativelayout

我正在使用“浮动操作菜单”,为此需要CoordinatorLayout。但是,如果我用CoordinatorLayout替换RelativeLayout的标签,那么所有的设计都搞砸了,所以我的问题是:如何将CoordinatorLayout放在RelativeLayout内?

RelativeLayout代码:

<RelativeLayout 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/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <ImageView
        android:layout_marginTop="?attr/actionBarSize"
        android:id="@+id/icon"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/shoppingcart"
        android:layout_width="100dp"
        android:layout_height="100dp"
    />

    <android.support.design.widget.TextInputLayout
        android:layout_below="@+id/icon"
        android:id="@+id/forgot_input_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText
            android:id="@+id/forgot_email"
            android:hint="Enter groceries"
            android:inputType="textCapWords"
            android:maxLines="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

        />
    </android.support.design.widget.TextInputLayout>
</RelativeLayout>

CoordinatorLayout代码:

        <android.support.design.widget.CoordinatorLayout>

            <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_main"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:fabSize="normal"
        app:srcCompat="@drawable/plus"
        />
        </android.support.design.widget.CoordinatorLayout>

我尝试过这样,但没有成功:

<RelativeLayout 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/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


        <ImageView
        android:layout_marginTop="?attr/actionBarSize"
        android:id="@+id/icon"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/shoppingcart"
        android:layout_width="100dp"
        android:layout_height="100dp"
    />

    <android.support.design.widget.TextInputLayout
        android:layout_below="@+id/icon"
        android:id="@+id/forgot_input_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText
            android:id="@+id/forgot_email"
            android:hint="Enter groceries"
            android:inputType="textCapWords"
            android:maxLines="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

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



        <android.support.design.widget.CoordinatorLayout>

            <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_main"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:fabSize="normal"
        app:srcCompat="@drawable/plus"
        />


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

</RelativeLayout>

0 个答案:

没有答案