圖1
看整個圖,用一個NestedScrollView包裹喉脖,最下面有兩個表亚隙,然后可以橫向滑動,我直接用橫向的HorizontalScrollView肠牲,里面加兩個RecyclerView幼衰,看起來貌似沒問題,在模擬器上跑著感覺也正常缀雳,然后跑到手機上渡嚣,會發(fā)現(xiàn),第一次進入頁面橫向滑動最下面的布局肥印,會直接把布局頂上去识椰。然后就正常了,滑動布局多了總會多多少少有些奇奇怪怪的問題
解決方法深碱,直接在NestedScrollView 外層布局添加android:descendantFocusability="blocksDescendants"腹鹉,viewgroup會覆蓋子類控件而直接獲得焦點
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/common_white"
android:descendantFocusability="blocksDescendants"
xmlns:zhy="http://schemas.android.com/tools">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
...
</androidx.core.widget.NestedScrollView>
</RelativeLayout>