在使用ScrollView時如果ScrollView內(nèi)有ListView或者RecyclerView等View時會發(fā)生直接滾動到底部的問題,這個時候可以將ScrollView上部顯示的某個View的focusable屬性和focusableInTouchMode屬性設(shè)置為true,例如:
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="38.5dp"/>
</LinearLayout>
</ScrollView>