ViewPager + SmartRefreshLayout + RecyclerView 导致最后一个 Item 显示不全 。

在996工作节奏下,解决了一个UI显示问题。具体为,在使用MagicIndicator+ViewPager和SmartRefreshLayout+RecyclerView时,RecyclerView在上拉加载到最后一页的最后一个Item出现显示不全的问题。通过调整ViewPager的高度设置,成功解决了此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在 996 ,不要问我啥感觉 ,就是突突 、 突突突 、突突突 。。。

 

 

小瑕疵

代码突突完之后 ,提测阶段遇到一个小瑕疵 。下面的 UI 图中 RecyclerView 在上拉加载到最后一页最后一个 Item 会出现显示不全的问题 。

 

页面结构

1. 使用 MagicIndicator + ViewPager  ( MagicIndicator —— Github

2. SmartRefreshLayout + RecyclerView  (SmartRefreshLayout —— Github

 

问题原因

最初的 xml 布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
    android:background="@android:color/white">

    <include
        android:id="@+id/view"
        layout="@layout/include_toolbar_layout" />

    <net.lucode.hackware.magicindicator.MagicIndicator
        android:id="@+id/magic_indicator"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/xdp_32"
        android:layout_marginTop="@dimen/xdp_15"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/view" />
 
    // ViewPager 高度为自适应
    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@id/magic_indicator" />

</android.support.constraint.ConstraintLayout>

 

在使用 ConstraintLayout 布局的时候 ,如果ViewPager 的高度使用自适应就会导致包含 Fragment 的RecyclerView 最后一个 Item 出现显示不全问题 。

 

解决

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
    android:background="@android:color/white">

    <include
        android:id="@+id/view"
        layout="@layout/include_toolbar_layout" />

    <net.lucode.hackware.magicindicator.MagicIndicator
        android:id="@+id/magic_indicator"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/xdp_32"
        android:layout_marginTop="@dimen/xdp_15"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/view" />

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/magic_indicator" />

</android.support.constraint.ConstraintLayout>

 

PS : 高度为 0dp ,使用 layout_constraintBottom_toBottoOf = " parent " 。

 

 

OK

 

ENG、

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值