原文:http://blog.csdn.net/airsaid/article/details/50723968
进入页面后,默认显示到ListView的第一条数据,ListView上方控件被挤掉。
解决方案:
在listView的根布局加上:
android:descendantFocusability="blocksDescendants"
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/color_other_bg" android:clipToPadding="true" android:fitsSystemWindows="true" android:descendantFocusability="blocksDescendants" android:orientation="vertical"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ImageView android:id="@+id/iv" android:layout_width="match_parent" android:layout_height="@dimen/x250" android:scaleType="centerCrop" /> <ListView android:id="@+id/lv_head_acupoint" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="@null" android:scrollbars="none" /> </LinearLayout> </ScrollView> </LinearLayout>
该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。
属性的值有三种:
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点