android - 滚动recylerview时如何使recylerview上方的文本滚动
问题描述
我有一个布局,它下面有标题 textview 和 recylerview。这一切都很好。但我试图让整个事情都可以滚动。这意味着如果我在添加新项目时向下滚动 rcylerview,我希望标题 textview 向上滚动(消失),就好像它是 recylerview 的一部分
这是我的xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:text="Near me"
android:textColor="@color/White"
android:textSize="21sp"
android:textStyle="bold" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvVideos"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
我知道我可以伪造它,因此 recylerview 的第 1 项具有不同的布局,即标题文本,但我希望有更好的选择,因此我不必处理项目数量和操纵位置的边缘情况
解决方案
您需要将 textview 和 recycler 视图都包装在NestedScrollView
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Textview"
android:layout_marginTop="10dp"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
我希望这会有所帮助......干杯
推荐阅读
- drupal - 如何连接代码以更改 Drupal 模块行为?
- python-3.x - 在 Seaborn 中:ValueError:2583019x1677798 像素的图像尺寸太大。每个方向必须小于 2^16
- javascript - 迭代与递归的大 O 区别是什么?
- ios - How can I detect programmatically (egIBAction) when the tab selection changes views?
- date - 如何在 Talend 中过滤日期?
- npm - 找不到已安装的包
- sql - 函数不起作用:错误:“删除”处或附近的语法错误
- visual-studio - 连接到布局渲染器失败,Java 错误?
- docker - 构建 Dockerfile 中指定的所有目标?
- sql - 有没有办法为每个“组”提取一个与同一组中的其他价格重复的记录?