Gallery和ListView共存焦点问题
项目中需要用到一个Gallery在最上方显示轮播图片,下面是一个ListView列表,外层用Scrollview包围,关于ListView高度的问题在这里有讲解
运行出来,Gallery被顶到上面去了,看到的是ListView,这说明ListView获得了焦点,xml文件中已经设置了
android:focusable="false"
android:focusableInTouchMode="false"
还需要设置什么呢?
解决方法:
在Gallery中加上 android:descendantFocusability="blocksDescendants"
android:descendantFocusability属性表示viewGroup和其子控件两者之间的相关
有三个值 beforeDescendants:viewgroup会优先其子类控件而获取到核心
afterDescendants:viewgroup只有当其子类控件不必要获取核心时才获取核心
blocksDescendants:viewgroup会包围子类控件而直接得到核心