在RecyclerView下方显示LinearLayout

时间:2016-04-30 11:42:39

标签: android android-layout android-recyclerview

我使用RecyclerView来显示项目列表,我想在列表下方显示一个包含一些详细信息的框,但我不知道该怎么做,我有尝试过很多东西,但是我无法显示我想要的盒子。

我的想法是实现如下图所示:

enter image description here

以下是我的代码:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="...MainActivity"
    android:background="@color/backgroundColor">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/user_subscriptions"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="12dp"
        android:paddingBottom="10dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


     // HERE I'M TRYING TO ADD THE BOX.


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_add" />

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

知道我该怎么办?谢谢!

6 个答案:

答案 0 :(得分:9)

试试这个希望这会对你有帮助。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        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_above="@+id/bottomBox"
        android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary" />

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/user_subscriptions"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="10dp"
            android:paddingTop="12dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="15dp"
            android:background="@color/colorPrimary" />


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

    <LinearLayout
        android:id="@+id/bottomBox"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:background="@android:color/white"
        android:orientation="vertical" />

</RelativeLayout>

答案 1 :(得分:1)

使用 app:layout_behavior =“@ string / appbar_scrolling_view_behavior ,如下所示: -

    <?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="...MainActivity"
    android:background="@color/backgroundColor">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/user_subscriptions"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="12dp"
        android:paddingBottom="10dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


    <LinearLayout
    android:id="@+id/bottomBox"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior
    android:background="@android:color/white"
    android:orientation="vertical" />


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_add" />

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

答案 2 :(得分:0)

RecyclerView身高match_parent。因此,您无法在下方显示任何内容,因为它将占用所有屏幕高度。

答案 3 :(得分:0)

你可以这样做

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="...MainActivity"
    android:background="@color/backgroundColor">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    // HERE I'M TRYING TO ADD THE BOX.

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

        <View
            android:id="@+id/box"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/user_subscriptions"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="12dp"
            android:paddingBottom="10dp"
            android:layout_above="@id/box"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    </RelativeLayout>


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_add" />

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

答案 4 :(得分:0)

我尝试了如何在视图下方的Recyclerview中强制执行,我意识到这是一项简单的任务。

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:fillViewport="true">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
        <LinearLayout
            android:id="@+id/line1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_gravity="center"
            android:padding="16dp">

            <Button
                android:layout_below="@+id/recycler_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Create Group"
                android:layout_gravity="center"
                style="@style/Button.Primary"/>
            <ImageView
                android:id="@+id/image_view_group_image"
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:layout_margin="16dp"
                android:layout_gravity="center"
                android:scaleType="centerInside"
                android:background="@color/colorPrimary"
                android:src="@drawable/ic_edit_white_24dp"/>
            <TextView
                android:layout_below="@+id/image_view_group_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="16dp"
                android:layout_gravity="center"
                android:text="Please add an icon for your group"/>
            <android.support.design.widget.TextInputLayout
                android:id="@+id/text_input_layout1"
                android:layout_below="@+id/image_view_group_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="8dp"
                android:hint="Type your group subject here">
                <android.support.design.widget.TextInputEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/text_input_layout"
                android:layout_below="@+id/text_input_layout1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="8dp"
                android:hint="Add Members">
                <android.support.design.widget.TextInputEditText
                    android:id="@+id/text_input_layout_add_members"
                    android:layout_width="match_parent"
                    android:drawableRight="@drawable/ic_search_grey_600_24dp"
                    android:drawableEnd="@drawable/ic_search_grey_600_24dp"
                    android:layout_height="wrap_content" />
            </android.support.design.widget.TextInputLayout>
        </LinearLayout>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_below="@+id/line1"
        android:layout_marginTop="16dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</RelativeLayout>

答案 5 :(得分:0)

如果要与其他视图(例如TextView,Button另一个recycleView ....)一起显示RecycleView,则可以使用NestedScrollView,例如:https://stackoverflow.com/a/63266559/7308789