【问题标题】:Is there any way to put recyclerview and linearlayout in swiperefreshlayout?有没有办法将recyclerview和linearlayout放在swiperefreshlayout中?
【发布时间】:2019-05-24 16:45:38
【问题描述】:

如果我只将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>

有没有办法解决这个问题?

【问题讨论】:

    标签: android android-layout kotlin android-recyclerview


    【解决方案1】:

    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>
    

    【讨论】:

    • 谢谢!我尝试了带有按钮的线性布局,它可以工作。
    猜你喜欢
    • 1970-01-01
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多