美文网首页
android:descendantFocusability用法

android:descendantFocusability用法

作者: 磐龍 | 来源:发表于2021-03-17 10:49 被阅读0次

    项目中的listview不仅仅是简单的文字,常常需要自己定义listview,自己的Adapter去继承BaseAdapter,在adapter中按照需求进行编写,诸如ImageButton,Button,CheckBox等子控件(也可以说是Button或者Checkable的子类控件)此时这些子控件会将焦点获取到,所以常常当点击item时变化的是子控件,item本身的点击没有响应。
    android:descendantFocusability

    Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.
    Must be one of the following constant values.

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

    beforeDescendants:viewgroup会优先其子类控件而获取到焦点
    afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
    blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
    

    用法是在item 里的RelativeLayout 加入android:descendantFocusability="beforeDescendants"

    相关文章

      网友评论

          本文标题:android:descendantFocusability用法

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