簡體   English   中英

RecyclerView 截斷最后一項

[英]RecyclerView cutting off last item

在此處輸入圖像描述我們可以在這里看到最后一項是部分可見的。 我怎樣才能解決這個問題? 布局.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>

我也有同樣的問題。 在我看來,這是因為您設置了 AppBarLayout XML 屬性 android:fitsSystemWindows="true"。 為了解決這個問題,我給 RecyclerView 邊距底部等於操作欄大小

 <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 是正確的問題是 RecyclerView 的 wrap_content 高度。 但是更改 match_parent 不起作用,因為。 此布局已添加到片段中,並且該片段被聲明為 wrap_content。 所以我將片段的高度和recyclerview的高度更改為match_parent,現在問題解決了。

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

我在ConstraintLayout中的RecyclerView遇到了這個問題,我將我的 recyclerview 約束更改為“0dp”(match_constraint)並且沒有進一步的麻煩。

看一看

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

如果你想使用tools:itemCount="28"你必須在你的XML文件中導入xmlns:tools="http://schemas.android.com/tools"

我嘗試了大多數可能站點的所有可用選項,但沒有得到解決方案。 那么,我想我可以使用底部填充嗎? 是的,這對我有用。

我把代碼分享給你。 除了高度、寬度和填充之外,不需要更多屬性。

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。它對我有用。

我正在展示一些解決方案但沒有用現在我找到了一個簡單的解決方案來切斷回收站視圖中的最后一項

將您的回收站視圖添加到 LinearLaout

將回收器視圖添加到 Linearlayout 后,將這兩個屬性添加到回收器視圖中。

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

現在,您的 Recyclerview 看起來像這樣,

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

最簡單但不是最好的解決方案。 仍然有效;

RecyclerView.Adapter實現的getItemCount()方法中返回 +1,並將代碼包裝在使用try-catch塊覆蓋的onBindViewHolder方法中。

對於其他人。在 recyclerview 中禁用嵌套滾動也會導致 CoordinatorLayout 出現此問題,並帶有可滾動的工具欄或 tablayout。 因為當您滾動 recyclerview 時,工具欄或 tablayout 不會滾動。

不要將 recyclerview 與任何視圖對齊..只需使其匹配父級並從頂部提供邊距....這對我有用

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM