<ScrollView android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="30dp">
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="16dp" />
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="16dp" />
<android.support.v7.widget.RecyclerView android:id="@+id/rv_homework" android:layout_width="match_parent" android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
复制代码
但是当这样写的时候,你会发现,RecyclerView会把它上面的视图顶出屏幕,而后要手动向下滑才能看到,出现这个问题是由于RecyclerView抢了焦点,咱们只须要在ScrollView的惟一子布局下面加上这么一句android
android:descendantFocusability="blocksDescendants"
复制代码
<LinearLayout android:descendantFocusability="blocksDendants" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="30dp">
复制代码
android:descendantFocusability该属性是当一个为view获取焦点时,定义viewGroup和其子控件二者之间的关系。布局
属性的值有三种:spa
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不须要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接得到焦点
复制代码