关于含RecyclerView的fragment来回切换时页面自动滑动到底部的解决方法
原因:
在fragment中来回切换时RecyclerView获得了焦点,而RecyclerView的 focusableOnTouchMode属性默认是true,所以在切换时RecyclerView自动获得焦点就滚动到了底部。
解决办法:
将RecyclerView上面的控件的设置android:focusableInTouchMode="true"(若无上方控件建议加一个不影响布局的View),如:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:background="#bfbfbf"
android:focusable="true"
android:focusableInTouchMode="true"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingRight="8dp"
android:paddingLeft="8dp"
android:fadingEdge="none">
</android.support.v7.widget.RecyclerView>
</LinearLayout> 相关推荐
sfhong00 2020-06-05
sheikhdz 2020-05-18
chenjinlong 2020-05-05
安辉 2020-04-30
chenjinlong 2020-02-03
magic00 2019-12-24
fengyeezju 2019-12-12
magic00 2019-10-21
whale 2019-06-30
DaLei 2019-06-30
mbcsdn 2019-06-28
yinbaoshiguang 2019-06-27
whale 2019-06-26
Palingenesis 2019-06-26