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

最近在 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、

发布了57 篇原创文章 · 获赞 40 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_37492806/article/details/103279028