android ViewTreeObserver

 android ViewTreeObserver从字面意思可以看出是View树的观察者。用法大致就是添加各种回调函数,包括但不限于draw方法开始执行,触摸模型改变,窗口状态改变,layout状态改变。


/**view树是否绑定到了Window上
     */
    public interface OnWindowAttachListener {
        /**
         * view绑定到了window上
         */
        public void onWindowAttached();


        /**
         * view从window上移除
         */
        public void onWindowDetached();
    }


    /**view书在窗口上的状态改变
     */
    public interface OnWindowFocusChangeListener {

        public void onWindowFocusChanged(boolean hasFocus);
    }


    /**view树焦点发生变化
     */
    public interface OnGlobalFocusChangeListener {
        /**
         * Callback method to be invoked when the focus changes in the view tree. When
         * the view tree transitions from touch mode to non-touch mode, oldFocus is null.
         * When the view tree transitions from non-touch mode to touch mode, newFocus is
         * null. When focus changes in non-touch mode (without transition from or to
         * touch mode) either oldFocus or newFocus can be null.
         *
         * @param oldFocus The previously focused view, if any.
         * @param newFocus The newly focused View, if any.
         */
        public void onGlobalFocusChanged(View oldFocus, View newFocus);
    }


    /**
     * 当全局布局状态或视图树中的视图的可见性改变时时,调用回调函数的接口定义。
     */
    public interface OnGlobalLayoutListener {
        /**
         * Callback method to be invoked when the global layout state or the visibility of views
         * within the view tree changes
         */
        public void onGlobalLayout();
    }


    /**
     * 当视图树要绘制时,调用回调函数的接口定义。
     */
    public interface OnPreDrawListener {
    
        public boolean onPreDraw();
    }


    /**
     * 当视图树要绘制时,调用回调函数的接口定义。
     */
    public interface OnDrawListener {

        public void onDraw();
    }




    /**view树内部滑动
     */
    public interface OnScrollChangedListener {
        /**
         * Callback method to be invoked when something in the view tree
         * has been scrolled.
         */
        public void onScrollChanged();
    }




    




posted @ 2016-09-07 11:17  清澈见底  阅读(146)  评论(0编辑  收藏  举报