Set RecyclerView max height


Introduce the constraintlayout library in build.gradle through ConstraintLayout settings

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

Set the parent layout of RecyclerView to ConstraintLayout, set the height of RecyclerView to 0dp, add layout_constraintHeight_min and layout_constraintHeight_max attributes, and specify the corresponding height

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/new_focus_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="11dp"
        android:overScrollMode="never"
        android:scrollbars="none"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:layout_constraintTop_toBottomOf="@+id/tv_new_focus"
        app:layout_constraintHeight_min="100dp"
        app:layout_constraintHeight_max="230dp" />

In this way, if the RecyclerView contains multiple items, its height can only display 230dp at most, and other items can be viewed by sliding.

Guess you like

Origin blog.csdn.net/Billy_Zuo/article/details/131707822