自定义View从实现ondraw开始;创建(onFininshInflate等)/布局(onMeasure,onLayout,onSizeChanged)/绘制/事件处理(onTrackballEvent,onTouchEvent等)/焦点(onFocusChanged,onWindowFocusChandge等)/绑定(onAttachedToWindow,onDetachedFromWindow,onWindowVisibilityChanged等);
framework负责调用onmeasure -> onlayout -> ondraw;程序中不能直接调用(除非实现了ViewGroup);View.setMeasuredDimension必须由View.onMeasure()调用;View.layout(); //为View指定尺寸和位置。
View Position:getRight()相当于getLeft()+getWidth(); getMeasureWidth和getWidth的差距在padding;
View Layout:重新布局调requestLayout方法。
View Draw:重绘制调invalidate方法;framework不绘制无效区域的view;
View Focus Handling:setFocusable()和setFocusableInTouchMode(); 移动指定下一焦点newtFocusDown/nextFocusLeft/nextFocusRiht/nextFocusUp;获取焦点requestFocus();
View Tags:存储额外数据,不是唯一标识。
View Security:setFilterTouchesWhenObscured()和onFilterTouchEventForSecurity(); 被遮挡时,对事件进行过滤/或者 屏蔽事件;
View Animation: startAnimation (Animation anim); ViewPropertyAnimator的使用。
View.MeasureSpec利用32位int,封装了父类对子类的限制模式和实际尺度;
View.post(new Runnable(){ public void run(){*****} }); //Causes the Runnable to be added to the message queue.
View.getLocationOnScreen(); //View相对与窗口的坐标值。
View实现Drawable.Callback,KeyEvent.Callback,AccessibilityEventSource;
Drawable.Callback接口,动画相关,与android.os.Handler#postAtTime(Runnable, Object, long)功能部分一致;KeyEvent.Callback接口,按键操作相关;AccessibilityEventSource接口,交互方式处理;
TextView(继承View实现ViewTreeObserver.OnPreDrawListener);ViewTreeObserver.OnPreDrawListener接口只有一个方法,当view tree将要draw时调用onPreDraw方法,调整滚动边框或者请求新的布局;
SurfaceView继承View;
View的computeScroll():Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary. This will typically be done if the child is animating a scroll using a {android.widget.Scroller Scroller} object.
Switch按钮 --> CompoundButton --> Button --> TextView --> View --> Object.
SimpleAdapter类 --> BaseAdapter,实现Filterable接口 --> 实现ListAdapter, SpinnerAdapter接口;ListAdapter接口继承了Adapter接口。
TextSwitcher/ImageSwitcher控件 --> ViewSwitcher --> ViewAnimator --> FrameLayout --> ViewGroup(继承View,实现ViewParent,ViewManager) --> View。
ViewSwitcher.ViewFactory接口,只有一个抽象方法makeView();ViewSwitcher的obtainView()方法中调用makeView()。
ViewFlipper控件 --> ViewAnimator --> FrameLayout --> ViewGroup(继承View,实现ViewParent,ViewManager) --> View。
ViewFlipper可以用来指定FrameLayout内多个View之间的切换效果,可以一次指定也可以每次切换的时候都指定单独的效果。
ListView/GridView控件 --> AbsListView --> AdapterView<T extends Adapter> --> ViewGroup(继承View,实现ViewParent,ViewManager) --> View。
Spinner控件 --> AbsSpinner --> AdapterView<T extends Adapter> --> ViewGroup --> View。
ViewManager接口有addView();updateViewLayout();removeView();添加或移除activity的child view; ViewParent接口定义了与parent view交互。
范型的使用,AdapterView<T extends Adapter>,强制转换是自动和隐式的,提高代码重用率;之前对类行Object实现参数任意化,需要显示的强制类型转换,编译器可能不提示错误,在运行的时候才出现异常。
范型extends类或接口;范型通配符,不单可以向下限制<? extends Collection>,也可以向上限制<? super Double>;是否拥有范型方法与所在的类是否为范型诶有关系,只需将范型参数列表置于返回值前。
LayoutInflater,通过系统服务获取,即context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)。