如何滚动整个页面,rocyclerview在scrollview的内部

发布于 2025-02-10 03:18:24 字数 2974 浏览 1 评论 0原文

我正在尝试在视频中实现相同的结构,但我的活动不会向下滚动。 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

I am trying to do this one

My design

<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

Final result

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁的年少不轻狂 2025-02-17 03:18:25

将此属性添加到您的recyclerview,

android:nestedScrollingEnabled="false"

如果它不起作用,请使用NestedScrollview而不是ScrollView

add this attribute to your RecyclerView

android:nestedScrollingEnabled="false"

if it doesn't work, use NestedScrollView instead of ScrollView

岁月无声 2025-02-17 03:18:25

您需要将recyclerview高度设置为wrap_content,然后将活动的所有XML放在scrollview中以获取所需的结果。

您的XML应该看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content"
    android:fillViewport="true"
    >

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:adjustViewBounds="true"
            tools:srcCompat="@tools:sample/backgrounds/scenic" />

        <!-- Your Ui Here: The ImageView is just for test -->

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/x"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toBottomOf="@id/imageView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            tools:itemCount="100"
            />
        
    </androidx.constraintlayout.widget.ConstraintLayout>
    
</ScrollView>

You need to set your RecyclerView height as wrap_content, and put all your xml of your activity inside a ScrollView to get the result that you want.

Your Xml should look like this :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content"
    android:fillViewport="true"
    >

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:adjustViewBounds="true"
            tools:srcCompat="@tools:sample/backgrounds/scenic" />

        <!-- Your Ui Here: The ImageView is just for test -->

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/x"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toBottomOf="@id/imageView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            tools:itemCount="100"
            />
        
    </androidx.constraintlayout.widget.ConstraintLayout>
    
</ScrollView>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文