この記事について
NestedScrollView内にあるViewを置いてからRecyclerViewを置いた時に、RecyclerViewの上端にスクロールされてしまい、最初に置いたViewが隠れてしまう問題に遭遇したので、対処法をメモする。
問題の詳細
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="このViewが隠れてしまう" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
上記のようにレイアウトを作って、RecyclerViewにAdapterをセットした場合、RecylcerViewの上端にスクロールされた状態で表示され、TextViewは上にスクロールしないと表示されなかった。
解決策
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical">
~ 省略 ~
</LinearLayout>
NestedScrollView直下のViewGroup(今回はLinearLayout)に android:focusableInTouchMode="true"
をつける
参考