MobileDeviceTalks 2018-05-26
原因:
在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>