如何滚动整个页面,rocyclerview在scrollview的内部
我正在尝试在视频中实现相同的结构,但我的活动不会向下滚动。 recyclerview卷轴,但我想像视频
中 的整个页面滚动整个页面a href =“ https://i.sstatic.net/wvtdq.gif” rel =“ nofollow noreferrer”>我的设计
<ScrollView>
<androidx.constraintlayout.widget.ConstraintLayout>
...
...
...
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/x"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
我解决了这个示例结构的问题。 注意:如果使用scrollView代替嵌套的crollview,则组件会滑动一点
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="@color/base"
android:clickable="true"
android:orientation="vertical"
tools:context=".Fragment.BasketFragment">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tb_BasketFragment"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/white"
android:elevation="4dp"
app:title="@string/title_basket"
app:titleTextAppearance="@style/Toolbar.TitleText"
app:titleTextColor="@color/black" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/acb_FragmentBasket"
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="26dp"
android:background="@drawable/custom_background_2"
android:text="@string/continue_shopping"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="16sp"
app:itemRippleColor="@null" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_FragmentBasket"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
i am trying to implement same structure in video but my activity not scrolling down. Recyclerview scrolls but i want to scroll whole page like in video
<ScrollView>
<androidx.constraintlayout.widget.ConstraintLayout>
...
...
...
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/x"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
I solved my problem with this example structure.
Note: if you use ScrollView instead of NestedScrollView, components slide a bit different
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="@color/base"
android:clickable="true"
android:orientation="vertical"
tools:context=".Fragment.BasketFragment">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tb_BasketFragment"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/white"
android:elevation="4dp"
app:title="@string/title_basket"
app:titleTextAppearance="@style/Toolbar.TitleText"
app:titleTextColor="@color/black" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/acb_FragmentBasket"
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="26dp"
android:background="@drawable/custom_background_2"
android:text="@string/continue_shopping"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="16sp"
app:itemRippleColor="@null" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_FragmentBasket"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将此属性添加到您的recyclerview,
如果它不起作用,请使用NestedScrollview而不是ScrollView
add this attribute to your RecyclerView
if it doesn't work, use NestedScrollView instead of ScrollView
您需要将
recyclerview
高度设置为wrap_content
,然后将活动的所有XML放在scrollview
中以获取所需的结果。您的XML应该看起来像这样:
You need to set your
RecyclerView
height aswrap_content
, and put all your xml of your activity inside aScrollView
to get the result that you want.Your Xml should look like this :