有什么办法可以将recyclerview和linearlayout放入swiperefreshlayout中吗?

时间:2019-05-24 07:33:22

标签: android android-layout kotlin android-recyclerview

如果我仅将RecyclerView放入SwipeRefreshLayout,则在RecyclerView上方有按钮。如果我全都放进SwipeRefresh,我的按钮就会消失

<android.support.v4.widget.SwipeRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipe_container"
        android:layout_width="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
            android:id="@+id/students_list"
            android:layout_width="match_parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            android:layout_height="0dp"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toTopOf="@+id/buttonsLayout">
    </android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>

<LinearLayout
        android:id="@+id/buttonsLayout"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        android:orientation="horizontal">

    <android.support.v7.widget.AppCompatButton
            android:id="@+id/selectAllButton"
            android:text="Выбрать всех"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
</LinearLayout>

有什么办法可以解决这个问题?

1 个答案:

答案 0 :(得分:0)

SwipeRefreshLayout仅接受一个孩子,因此也许您可以在SwipeRefreshLayout内部拥有一个ConstraintLayout,并在ConstraintLayout内部具有带有按钮的RecyclerView。

PS:我建议使用ConstraintLayout以避免嵌套布局。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.constraint.ConstraintLayout>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/students_list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toTopOf="@+id/selectAllButton"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

        <android.support.v7.widget.AppCompatButton
            android:id="@+id/selectAllButton"
            android:text="Выбрать всех"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toBottomOf="parent" />
    </android.support.constraint.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout>
相关问题