android ListItem 焦点获取问题
16lz
2021-01-23
通常Android提供给我们的ListItem布局不是我们需要,可能我们想在里面添加一些图片,按钮等等,但是这时候这些可以获得焦点的子控件将会提前获取焦点,从而Item没有了获取焦点的能力了,这时候我们需要设置子控件获取焦点的能力为false,但是如果子控件较多时,这样设置比较麻烦,我们可以在我们自定义的item的根属性下添加:android:descendantFocusability="blocksDescendants"这样item将会阻止子控件获取焦点。该属性还有其他两种可能:"beforeDescendants"和"afterDescendants"。分别为在子控件之前和之后。
/** * This view will get focus before any of its descendants. */ public static final int FOCUS_BEFORE_DESCENDANTS = 0×20000; /** * This view will get focus only if none of its descendants want it. */ public static final int FOCUS_AFTER_DESCENDANTS = 0×40000; /** * This view will block any of its descendants from getting focus, even * if they are focusable. */ public static final int FOCUS_BLOCK_DESCENDANTS = 0×60000;
/** * This view will get focus before any of its descendants. */ public static final int FOCUS_BEFORE_DESCENDANTS = 0×20000; /** * This view will get focus only if none of its descendants want it. */ public static final int FOCUS_AFTER_DESCENDANTS = 0×40000; /** * This view will block any of its descendants from getting focus, even * if they are focusable. */ public static final int FOCUS_BLOCK_DESCENDANTS = 0×60000;
/** * This view will get focus before any of its descendants. */
public static final int FOCUS_BEFORE_DESCENDANTS = 0×20000;
/** * This view will get focus only if none of its descendants want it. */
public static final int FOCUS_AFTER_DESCENDANTS = 0×40000;
/** * This view will block any of its descendants from getting focus, even * if they are focusable. */
public static final int FOCUS_BLOCK_DESCENDANTS = 0×60000;
更多相关文章
- Android的EditText自动获取焦点并弹出输入法问题
- Android属性动画实战教程中篇
- Android原生Switch控件滑块thumb卡住问题的解决方法
- Tablayout属性以及设置行间距和列间距
- android控件的监听绑定方法
- android 主要的布局控件简介
- 相对布局的layout_alignLeft属性