简体   繁体   中英

RecyclerView cutting off last item

在此处输入图像描述We can see here last item is partially visible. How can i fix this? layout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinator_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <include
                layout="@layout/header"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

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

</android.support.design.widget.CoordinatorLayout>

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/grey_background">

    <ImageView
        android:id="@+id/image"
        android:layout_width="@dimen/thumbnail_width"
        android:layout_height="@dimen/thumbnail_height"
        android:layout_gravity="center"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@id/image"
        android:orientation="vertical"
        android:padding="@dimen/participant_left_padding">

        <TextView
            android:id="@+id/participants_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="name"
            android:textColor="@android:color/white"/>

        <TextView
            android:id="@+id/total_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="view"
            android:textColor="@android:color/white"/>

        <TextView
            android:id="@+id/ranking"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ranking"
            android:textColor="@android:color/white"/>
    </LinearLayout>

    <ImageView
        android:id="@+id/overflow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:src="@drawable/ic_action_overflow"/>
</RelativeLayout>

I'm also having the same problem. In my opinion this happened because you set the AppBarLayout XML attribute android:fitsSystemWindows="true". To solve this i give the RecyclerView margin bottom equal to action bar size

 <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:id="@+id/recyclerView"
        android:layout_marginBottom="?attr/actionBarSize">

@Lester was right problem was RecyclerView's wrap_content height. But changing match_parent was not working because. This layout was added to a fragment and that fragment was declared wrap_content. So I have changed fragment's height and recyclerview's height to match_parent and now problem solved.

<fragment
        android:id="@+id/fragment"
        android:name="com.example.fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

I had this problem with a RecyclerView inside a ConstraintLayout , and i changed my recyclerview constriants to "0dp" (match_constraint) and had no further trouble.

have a look

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <!-- Title -->
    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/view_with_press_height"
        android:text="@string/taxes_fees_charges"
        android:gravity="center_vertical"
        android:layout_marginStart="@dimen/general_side_margin"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />

   <!-- Details Recyclerview-->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/title"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="@dimen/general_bottom_margin"
        app:layout_constraintVertical_bias="0.0"
        tools:itemCount="28"
        tools:listitem="@layout/tax_details_row" />

</android.support.constraint.ConstraintLayout>

if you want to use the tools:itemCount="28" you will have to import xmlns:tools="http://schemas.android.com/tools" in your XML file.

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

使用 RelativeLayout 而不是 ConstraintLayout。它对我有用。

I'm showing some solution but didn't work Now I find one easy solution for this cutting off the last item in recycler view

Add your recycler view into LinearLaout

After adding recycler view into Linearlayout add these two Attributes into recycler view.

android:paddingBottom="?attr/actionBarSize"
android:clipToPadding="false"

Now, Your Recyclerview looks like this,

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rvQuotes"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="@dimen/_10sdp"
        android:layout_marginEnd="@dimen/_10sdp"
        android:background="@color/white"
        android:paddingBottom="?attr/actionBarSize"
        android:paddingTop="@dimen/_10sdp"
        android:clipChildren="false"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        tools:listItem="@layout/item_dessert"
        android:clipToPadding="false"/>

Easiest but not the best solution. Still works;

Return +1 in the getItemCount() method of your RecyclerView.Adapter implementation and wrap your code in onBindViewHolder method override with a try-catch block.

For others.Disabling nested scrolling in recyclerview also causes this problem in CoordinatorLayout with scrollable toolbar or tablayout. Because when you scroll recyclerview, toolbar or tablayout doesn't scroll.

don't align recyclerview with respect to any view.. simply make it match parent and provide margin from top....this worked for me

 <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerViewAddresses"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            android:layout_marginTop="@dimen/dimen_120dp"
            />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM