NestedScrollView 里面包含RecycleView和Fragment,在加载数据后,后加载的Fragment覆盖了部分RecycleView数据。
原因是NestedScrollView 子View设置了margintop和marginbottom,改成padding就可以了
问题代码 :
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:fillViewport="true"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
android:focusableInTouchMode="true"
android:focusable="true"
android:layout_marginBottom="@dimen/dp16"
android:paddingLeft="@dimen/dp12"
android:paddingRight="@dimen/dp12">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:nestedScrollingEnabled="false"
android:layout_height="wrap_content"/>
<FrameLayout
android:layout_marginTop="@dimen/dp16"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:layout_marginTop="@dimen/dp16"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
修改后
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:fillViewport="true"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants"
android:focusableInTouchMode="true"
android:focusable="true"
android:paddingTop="@dimen/dp16"
android:paddingBottom="@dimen/dp20"
android:paddingLeft="@dimen/dp12"
android:paddingRight="@dimen/dp12">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_employed"
android:layout_width="match_parent"
android:nestedScrollingEnabled="false"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/fl_all_employed"
android:layout_marginTop="@dimen/dp16"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/fl_other_employed"
android:layout_marginTop="@dimen/dp16"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>