美文网首页
ListView有Button抢焦点使Item不能点击 Vie

ListView有Button抢焦点使Item不能点击 Vie

作者: gerg_peng | 来源:发表于2016-09-15 10:55 被阅读256次

一、ListView的item布局中有Button时,item无法点击:

解决方法:

Item布局的根布局加上android:descendantFocusability=”blocksDescendants”

同时给button加上 focusable = false;


descendantFocusability相关知识:

API:

该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。

属性的值有三种:

beforeDescendants:viewgroup会优先其子类控件而获取到焦点

afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点

blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点

二、ViewPager有button等,无法侧滑

问题描述:

        ViewPager的一个Fragment中的布局是一个ListView,然后其中添加了三排水平排列的Button,手放到button上无法侧滑。

button的布局中加了一个android:singleLine="true"

解决方法:

        问题就出现在这个android:singleLine="true"上,此属性是一个过时的属性,至于为啥让ViewPager无法侧滑,原因尚不清楚。解决办法就是删除此属性,用

android:lines="1"

android:scrollHorizontally="true"  替代就可以了。

相关文章

网友评论

      本文标题:ListView有Button抢焦点使Item不能点击 Vie

      本文链接:https://www.haomeiwen.com/subject/vdrbettx.html