我有一个包含 ImageView 和 RecyclerView 的 Scrollview。如果导航抽屉打开然后关闭 RecyclerView 自动滚动到顶部,如何停止这个?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollViewMain"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView_main_icons_line"
android:src="@drawable/main_line" />
...
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_activity_main_passenger_log"
android:paddingBottom="2dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
原文由 Samad 发布,翻译遵循 CC BY-SA 4.0 许可协议
这个问题是因为 recyclerView 有默认焦点。
添加
android:descendantFocusability="blocksDescendants"
到您的 scrollView 的直接布局