RecyclerView is cutting off the last item

前端 未结 19 2111
予麋鹿
予麋鹿 2020-12-02 18:47

I have a fragment with a toolbar and a recyclerView inside it.

I am populating the recyclerView with dummy data and then try to show them. For some reason, the last

相关标签:
19条回答
  • 2020-12-02 19:03
      <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="150dp"
      android:layout_marginStart="@dimen/_20"
        android:layout_marginEnd="@dimen/_20"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout">
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_Bookingagain"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:focusableInTouchMode="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent" />
    
    </RelativeLayout>
    
    0 讨论(0)
  • 2020-12-02 19:06

    Try to change your RecyclerView height to "wrap_content" and add the AppBarLayout height as margin bottom.

    <android.support.v7.widget.RecyclerView
            android:id="@+id/simpleList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/height_of_app_bar"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    

    The cut-off part of the list item, is the height of the AppBarLayout.

    0 讨论(0)
  • 2020-12-02 19:07

    Set layout_height="match_parent" then add layout_marginBottom="?attr/actionBarSize" or 50dp this will compensate for the ToolBar forcing the RecyclerView down cutting off the last view.

    Additionally set nestedScrollingEnabled="false" if you have a hideOnScroll enabled toolbar.

    <androidx.recyclerview.widget.RecyclerView
         android:id="@+id/my_recycler_view"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_marginBottom="?attr/actionBarSize"
         android:nestedScrollingEnabled="false"  />
    
    0 讨论(0)
  • 2020-12-02 19:07

    I had the same problem (even missing an entire ViewHolder element from my list) while using a RecyclerView inside a ConstraintLayout. As Sila Siebert mentioned, setting layout_width and layout_height of the RecyclerView to zero did the trick. It's a bit confusing cause the editor jumps back to say "match_constraints" after a bit while the XML-text says 0dp. Don't let it confuse you, it should work.

    0 讨论(0)
  • 2020-12-02 19:08

    You may try following as this is working as expected:

    <android.support.v7.widget.RecyclerView
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/layout_header">
    </android.support.v7.widget.RecyclerView>
    
    0 讨论(0)
  • 2020-12-02 19:09

    This worked for me. Set both height and width of the recyclerView to 0dp

     <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_materias"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="20dp"
        android:background="@color/secondaryLightColor"
        app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/guideline6"></android.support.v7.widget.RecyclerView>
    
    0 讨论(0)
提交回复
热议问题