ViewPager2 子page 是 recyclerview, 上划底部view 加载更多,正在加载,位置显示有问题。最后发现,是因为使用了约束布局。
<fly.component.widgets.EasyRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:finishLoadMore="@{viewModel.finishLoadMore}"
app:finishLoadMoreWithNoMoreData="@{viewModel.finishLoadMoreWithNoMoreData}"
app:finishRefresh="@{viewModel.finishRefresh}"
app:loadMoreAnimation="@{viewModel.loadMoreAnimation}"
app:onLoadMoreListener="@{viewModel.onLoadMoreListener}"
app:onRefreshListener="@{viewModel.onRefreshListener}"
app:refreshAnimation="@{viewModel.refreshAnimation}">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:adapter="@{viewModel.adapter}"
app:itemBinding="@{viewModel.itemBinding}"
app:items="@{viewModel.items}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</fly.component.widgets.EasyRefreshLayout>
<!-- 更改之前布局 -->
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
tools:ignore="ResourceName">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager2"
android:layout_width="match_parent"
android:layout_height="0dp"
app:fragments="@{viewModel.items}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/stickylayout_indicator"
app:userInputEnabled="@{true}" />
<fly.component.widgets.tabflowlayout.TabFlowLayout
android:id="@id/stickylayout_indicator"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="@dimen/activity_margin_h"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabPager2="@{viewPager2}"
app:tabSelectedColor="@{@color/indicator_tab_selected_color}"
app:tabTitles="@{viewModel.pagerTitles}"
app:tabUnSelectedColor="@{@color/indicator_tab_unselected_color}"
app:tab_height="3dp"
app:tab_item_autoScale="true"
app:tab_item_res="@drawable/home_selectline"
app:tab_scale_factor="1.4"
app:tab_type="res"
app:tab_width="16dp" />
<TextView
android:layout_width="35dp"
android:layout_height="21dp"
android:layout_marginRight="@dimen/activity_margin_h"
android:background="@drawable/shape_msg_count"
android:gravity="center"
android:text="发布"
app:bindClick="@{viewModel.publishClick}"
android:textColor="#ffffff"
android:textSize="11sp"
app:layout_constraintBottom_toBottomOf="@id/stickylayout_indicator"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/stickylayout_indicator" />
<!-- <androidx.recyclerview.widget.RecyclerView-->
<!-- app:layout_constraintTop_toBottomOf="@id/tabFlowLayout"-->
<!-- app:layout_constraintLeft_toLeftOf="parent"-->
<!-- app:layout_constraintRight_toRightOf="parent"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="0dp"-->
<!-- app:adapter="@{viewModel.adapter}"-->
<!-- app:itemBinding="@{viewModel.itemBinding}"-->
<!-- app:items="@{viewModel.items}"-->
<!-- app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />-->
<ImageView
android:layout_width="53dp"
android:layout_height="53dp"
android:layout_marginRight="9dp"
android:layout_marginBottom="9dp"
android:src="@mipmap/dynamic_release"
app:bindClick="@{viewModel.publishClick}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<data>
<variable
name="viewModel"
type="fly.business.dynamic.viewmodel.DynamicModel" />
</data>
</layout>
修改后布局,使用线性布局,不再有问题
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
tools:ignore="ResourceName">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fly.component.widgets.tabflowlayout.TabFlowLayout
android:id="@id/stickylayout_indicator"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="@dimen/activity_margin_h"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabPager2="@{viewPager2}"
app:tabSelectedColor="@{@color/indicator_tab_selected_color}"
app:tabTitles="@{viewModel.pagerTitles}"
app:tabUnSelectedColor="@{@color/indicator_tab_unselected_color}"
app:tab_height="3dp"
app:tab_item_autoScale="true"
app:tab_item_res="@drawable/home_selectline"
app:tab_scale_factor="1.4"
app:tab_type="res"
app:tab_width="16dp" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:fragments="@{viewModel.items}"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:userInputEnabled="@{true}" />
</LinearLayout>
<TextView
android:layout_width="35dp"
android:layout_height="21dp"
android:layout_gravity="right"
android:layout_marginTop="10dp"
android:layout_marginRight="@dimen/activity_margin_h"
android:background="@drawable/shape_msg_count"
android:gravity="center"
android:text="发布"
android:textColor="#ffffff"
android:textSize="11sp"
app:bindClick="@{viewModel.publishClick}" />
<ImageView
android:layout_width="53dp"
android:layout_height="53dp"
android:layout_gravity="right|bottom"
android:layout_marginRight="9dp"
android:layout_marginBottom="9dp"
android:src="@mipmap/dynamic_release"
app:bindClick="@{viewModel.publishClick}" />
</FrameLayout>
<data>
<variable
name="viewModel"
type="fly.business.dynamic.viewmodel.DynamicModel" />
</data>
</layout>