RecyclerView最後一條顯示不全或顯示部分的問題解決

一、問題現象

RecyclerView最後一條數據展示不全的問題

二、前提條件

使用ViewPager+Fragment+RefreshLayout+RecyclerView+constrainLayout

三、嘗試解決方式

什麼叫嘗試解決方式,就是使用了以下方式,各種修改各種沒解決。

1.recyclerview高度設置爲0dp,然後添加app:layout_constraintBottom_toBottomOf="parent"

2.recyclerview用NestedScrollView包起來

3.recyclerview外套RelativeLayout

如果以上嘗試都沒有解決你的問題、那麼好,接下來就是見證奇蹟的時刻了。

四、最終解決方案

使用CoordinatorLayout+AppBarLayout修飾viewPager完美解決~話不多說半句多。請看代碼

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/sv_contentView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/common_content_background_color">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/ll_contentView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:elevation="0dp">

        <ai.gmtech.uicom.ui.CommonTitleBar
            android:id="@+id/commonTitleBar26"
            android:layout_width="match_parent"
            android:layout_height="44dp"
            app:title="對講">


        </ai.gmtech.uicom.ui.CommonTitleBar>

        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tab_call"
            android:layout_width="match_parent"
            android:layout_height="44dp"
            android:background="@color/white_FFFFFFFF"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:tabIndicator="@drawable/tab_indictor_bg"
            app:tabIndicatorColor="@color/common_tv_font_color">

        </com.google.android.material.tabs.TabLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/bottom_view_cl"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:id="@+id/view_pager_rl"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_weight="1">

            <androidx.viewpager.widget.ViewPager
                android:id="@+id/callpage_viewPager"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            </androidx.viewpager.widget.ViewPager>
        </RelativeLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

五、若有其他問題及及解決方案歡迎留言探討

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章