RecyclerView is cutting off the last item

前端 未结 19 2109
予麋鹿
予麋鹿 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 18:53

    If you are using Constraint Layout, make sure the layout_height is 0dp and layout_constraintBottom_toBottomOf constraint is set properly.

      <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/titleTextView"
         />
    
    0 讨论(0)
  • 2020-12-02 18:53

    I know I am late, but today I faced the same issue. I have a ConstrantLayout, a toolbar, a recyclerview. So I used android:layout_height="match_parent", and to prevent the recyclerview from overlapping with the topbar, I used, app:layout_constraintTop_toBottomOf="@id/toolbar" android:layout_marginTop="?attr/actionBarSize"

    So the entire code looks something like this:

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:onClick="onClick"
        android:background="@color/shop_main_fragment_background"
        >
        <include layout="@layout/toolbar"/>
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rootRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_constraintTop_toBottomOf="@id/toolbar"
            android:layout_marginTop="?attr/actionBarSize"
            >
        </androidx.recyclerview.widget.RecyclerView>
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    I hope this is helpful.

    0 讨论(0)
  • 2020-12-02 18:55

    Create a FrameLayout put the RecycerView in it having it match_parent for both the width and the height. You can size the framelayout however you want.

    0 讨论(0)
  • 2020-12-02 18:59

    I tried all the available option from most of possible site but I didn't get the solution. Then, I think can I use bottom padding? And Yes, It's work for me.

    I am sharing the code to you. Nothing more attribute required other than height, width & padding.

    android:paddingBottom="?attr/actionBarSize"

     <android.support.v7.widget.RecyclerView
        android:id="@+id/your id name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="?attr/actionBarSize"
        app:layout_constraintTop_toBottomOf="@+id/your field" />
    
    0 讨论(0)
  • 2020-12-02 18:59

    You are missing the bottom constraint. You should add: app:layout_constraintBottom_toBottomOf="parent" on the recylerview.

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

    I had similar problem. Adding android:minHeight="?attr/actionBarSize" to CollapsingToolbarLayout helped.

    0 讨论(0)
提交回复
热议问题