android - 有没有办法将recyclerview和linearlayout放入swiperefreshlayout?
问题描述
如果我只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>
有没有什么办法解决这一问题?
解决方案
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>
推荐阅读
- mysql - 如何获取按日期排序的行的出现次数
- angular - navigator.clipboard.readText() 的等效代码是什么?
- .net - 在实体框架模型中将数据插入 SQL Server
- android - 为什么Intent中的类有“::class.java”后缀?
- c++ - 使用 push-relabel 计算最大流量时获取最小切割
- ios - 如何将 YUV 数据转换为 CVPixelBufferRef?
- excel - 如何在同一个 Excel 电子表格(VBA)中将多个行块写入单独的文件?
- scala - Scala 解析错误';' 预期但找到字符串文字
- asp.net - 在图表标签 asp.net 中格式化数字
- laravel - Vue SPA 和 Laravel 社交名流