gpt4 book ai didi

android - 如何使recyclerview显示所有项目并且无法滚动

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:30 29 4
gpt4 key购买 nike

我正在制作一个应用程序以在一个 View 中显示所有产品。我希望 recyclerview 显示所有项目并且不能滚动,只需滚动父 View ( ScrollView )。但问题是无法让回收器的高度包裹所有内容。

-->>I want like this

这是我的代码:

    <TextView
android:text="Best seller:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView4"
android:textColor="#3f3f3f"
android:textSize="18sp" />

<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:scrollbars="horizontal"
android:id="@+id/rv_bestSeller"
android:layout_height="200dp" />

<TextView
android:text="New Product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView5"
android:textSize="18sp"
android:textColor="#3f3f3f" />

<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:scrollbars="horizontal"
android:layout_height="200dp"
android:id="@+id/rv_newProduct"/>

<TextView
android:text="All Product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView6"
android:textSize="18sp"
android:textColor="#3f3f3f" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rv_allProduct" />
</LinearLayout>
</ScrollView>

-->>But the space is so small

最佳答案

您应该结合使用 NestedScrollViewsetNestedScrollingEnabled(false)

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>

</LinearLayout>
</android.support.v4.widget.NestedScrollView>

关于android - 如何使recyclerview显示所有项目并且无法滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41086051/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com