Last Item in recyclerview is cut off

前端 未结 5 1580
抹茶落季
抹茶落季 2020-12-31 06:03

I am using recyclerview to display a list of items and constraint layout is the parent view. The layout is displayed below:

  

        
相关标签:
5条回答
  • 2020-12-31 06:27

    Try using RelativeLayout instead of ConstraintLayout.

    It's working for me so it seems a problem with ConstraintLayout specifically.

    0 讨论(0)
  • 2020-12-31 06:28

    1)The View of Recyclerview must be properly constrained. (by ConstraintLayout or any other layout parameters).

    2)The Last item occupies the space inside the RecyclerView, hence use Padding. (e.g android:paddingBottom="50dp")

    3)Use android:clipToPadding="false" in XML.

    0 讨论(0)
  • 2020-12-31 06:30

    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.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-31 06:32

    Well in my case my ConstraintLayout's layout_height was wrap_content, that's why last item was cutting from bottom. So to resolve this: ConstraintLayout's layout_height should be either fixed or match_parent.

    0 讨论(0)
  • 2020-12-31 06:50

    Your RecyclerView is not properly constrained. You can either use 0dp (MATCH_CONSTRAINT) for the height and use all available space:

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="8dp"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar" />
    

    or if you want to keep it as wrap_content you will need to set app:layout_constrainedHeight="true" attribute to enforce the constraints:

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:visibility="visible"
        app:layout_constrainedHeight="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar" />
    
    0 讨论(0)
提交回复
热议问题