这个函数是在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);
- }
- }
通过这里的实现可以看到上面定义的三个常量设置的意思。。
相关推荐
android各组件详解- ViewGroup.pdf
这是android viewgroup view 源码,有一些注释,此源码仅供学习使用。
params.width = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;// 窗口宽度 params.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;// 窗口高度 manager.addView(layout, params); }
package wei.ye.g1;import android.app.Activity;...import android.view.ViewGroup.LayoutParams;import android.widget.BaseAdapter;import android.widget.Gallery;import android.widget.ImageView;
这回我们是深入到ViewGroup内部\,了解ViewGroup的工作...在这个类里定义了ViewGroup.LayoutParams类,这个类是布局参数的子类。 其实ViewGroup也就是View的容器。通过ViewGroup.LayoutParams来指定子View的参数。 V
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); iv.setLayoutParams(params); *使用文字 TextView iv = new TextView(this); iv.setText("欢迎使用"); iv.setTextColor(get...
ViewGroup.LayoutParams.MATCH_PARENT, 64); TextView textView = new TextView(ExpandableListDemo.this); textView.setLayoutParams(lp); // Center the text vertically textView.setGravity(Gravity....
代码为博客实例代码:http://blog.csdn.net/lmj623565791/article/details/38352503 有问题请博客留言
ViewGroupDemo.rar http://blog.csdn.net/wuchuang127/article/details/39225303
androidviewgroup侧滑面板实现附apk,稍后增加博客说明http://blog.csdn.net/qq_25566921/article/details/79176498
WindowManager属性详解:WindowManager.LayoutParams 是 WindowManager 接口的嵌套类;继承于 ViewGroup.LayoutParams 。 它的内容十分丰富。其实WindowManager.java的主要内容就是由这个类定义构成。
@Override public void getView(int position, View convertView, ViewGroup parent) { SquaredImageView view = (SquaredImageView) convertView; if (view == null) { view = new SquaredImageView(context); ...
EnterAnimation android 仿ppt进入动画效果合集, 百叶窗效果,擦除效果,盒状效果,阶梯效果...The Animation effects can apply to any View or ViewGroup. There is also a custom ViewGroup of auto linefeed calle
今天看到很多app都有Title自动隐藏功能,1.这是一个Gradle工程,Gradle的版本是2.10,项目的Compile sdk Version是 23 , Build ...Android自定义ViewGroup实现Title自动隐藏功能源代码分享,Android开发者必看示例。
import android.view.ViewGroup.LayoutParams; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; public class ...
可以指定圆角的ViewGroup
目录 1.基本介绍 2.代码示例 3.实现效果及便捷工具类 4.仿微信语音通话悬浮窗效果实现 ...addView(View view, ViewGroup.LayoutParams params) 主要通过该方法将指定 View 添加到屏幕上,实现悬浮窗效果 ( WindowMan
import android.content.Context; import android.view.LayoutInflater;...import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView;
android自定义viewGroup仿Scrollview详解