[英]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.