Android ViewGroup.setDescendantFocusability函数
来源:互联网 发布:在淘宝进货实体店买 编辑:程序博客网 时间:2024/06/10 05:55
转:http://flysnow.iteye.com/blog/1762556
Android ViewGroup.setDescendantFocusability函数
- 博客分类:
- Android
android ViewGroup 焦点
这个函数是在ViewGroup里定义的,主要用于控制child View获取焦点的能力,比如是否阻止child View获取焦点。
他有三个常量可供设置
- FOCUS_BEFORE_DESCENDANTS ViewGroup本身先对焦点进行处理,如果没有处理则分发给child View进行处理
- FOCUS_AFTER_DESCENDANTS 先分发给Child View进行处理,如果所有的Child View都没有处理,则自己再处理
- FOCUS_BLOCK_DESCENDANTS ViewGroup本身进行处理,不管是否处理成功,都不会分发给ChildView进行处理
我们看下这个方法的实现
- public void setDescendantFocusability(int focusability) {
- switch (focusability) {
- case FOCUS_BEFORE_DESCENDANTS:
- case FOCUS_AFTER_DESCENDANTS:
- case FOCUS_BLOCK_DESCENDANTS:
- break;
- default:
- throw new IllegalArgumentException("must be one of FOCUS_BEFORE_DESCENDANTS, "
- + "FOCUS_AFTER_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS");
- }
- mGroupFlags &= ~FLAG_MASK_FOCUSABILITY;
- mGroupFlags |= (focusability & FLAG_MASK_FOCUSABILITY);
- }
可以看到,只有这三个常量可以设置,不是这三个常量会抛出异常的。
设置后,会在requestFocus(int direction, Rect previouslyFocusedRect) 方法里根据设置进行相应的处理。来看下实现
- public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
- if (DBG) {
- System.out.println(this + " ViewGroup.requestFocus direction="
- + direction);
- }
- int descendantFocusability = getDescendantFocusability();
- switch (descendantFocusability) {
- case FOCUS_BLOCK_DESCENDANTS:
- return super.requestFocus(direction, previouslyFocusedRect);
- case FOCUS_BEFORE_DESCENDANTS: {
- final boolean took = super.requestFocus(direction, previouslyFocusedRect);
- return took ? took : onRequestFocusInDescendants(direction, previouslyFocusedRect);
- }
- case FOCUS_AFTER_DESCENDANTS: {
- final boolean took = onRequestFocusInDescendants(direction, previouslyFocusedRect);
- return took ? took : super.requestFocus(direction, previouslyFocusedRect);
- }
- default:
- throw new IllegalStateException("descendant focusability must be "
- + "one of FOCUS_BEFORE_DESCENDANTS, FOCUS_AFTER_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS "
- + "but is " + descendantFocusability);
- }
- }
通过这里的实现可以看到上面定义的三个常量设置的意思。。
0 0
- Android ViewGroup.setDescendantFocusability函数
- Android ViewGroup.setDescendantFocusability函数
- Android ViewGroup.setDescendantFocusability函数
- Android ViewGroup.setDescendantFocusability函数
- Android ViewGroup.setDescendantFocusability函数
- Android ViewGroup.setDescendantFocusability函数
- Android ViewGroup.setDescendantFocusability函数
- setDescendantFocusability
- setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS)会让所有子View无法获取焦点
- Android ViewGroup
- ViewGroup dispatchTouchEvent函数剖析
- 【Android】Android自定义ViewGroup
- Android控件 - ViewGroup、ViewGroup.LayoutParams、ViewGroup.MarginLayoutParams简介
- Android ViewGroup.resetResolvedLayoutDirection(ViewGroup.Java:6081)
- Android View、ViewGroup
- Android 之 View ViewGroup
- android之自定义ViewGroup
- android里的ViewGroup
- 再谈SipDroid
- 和字符串相关的一些问题
- innerHTML和innerText的用法(动态改变网页内容)
- pyqt界面控件
- 初学oracle 满天飞的都是错误代码
- Android ViewGroup.setDescendantFocusability函数
- 3a资源
- PAT-B 1002. 写出这个数 (python)
- 彻底删除jdk并重装jdk和配置环境变量设置后Error: could not open `F:\Java\jre7\lib\jvm.cfg
- Effective C++ 条款12 赋值对象时勿忘其每一个成分
- ZIP工具类
- LLVM简介
- java.io.IOException - Cannot run program "git": java.io.IOException: error=2, No such file or direct
- 宿主机mac os无法连接到虚拟机centos