一、問題現象
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>