簡體   English   中英

如何使recyclerview顯示所有項目,不能滾動

[英]How to make recyclerview show all item and can not scroll

我正在制作一個應用程序,以1視圖顯示所有產品。 我希望recyclerview顯示所有項目並且無法滾動,只需滾動父視圖(ScrollView)。 但問題是不能使回收者的高度包裹所有內容。

- >>我想這樣

這是我的代碼:

    <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>

- >>但空間太小了

這樣做是不好的做法,如果你這樣做是因為標題使用了這個庫https://github.com/emilsjolander/StickyListHeaders

它會給你標題,你不需要里面有列表的滾動視圖。

如果你真的想以這種方式繼續使用NestedScrollView而不是常規的Scrollview

https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html

這將允許你像你想要的那樣禁用嵌套滾動

您應該使用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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM