View的onFinishInflate和onViewAdded回调说明

来源:互联网 发布:java产生随机数的方法 编辑:程序博客网 时间:2024/06/03 03:39

------- 代码

① 何时回调这2个方法已经在代码里说明。

public class MyFrameLayout extends FrameLayout {    public MyFrameLayout(Context context) {        this(context, null);    }    public MyFrameLayout(Context context, AttributeSet attrs) {        this(context, attrs, -1);    }    public MyFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    /**     * View本身在xml中被引用,被解析完成,由View本身的父View回调该方法     */    @Override    protected void onFinishInflate() {        super.onFinishInflate();        Toast.makeText(getContext(), getClass().getSimpleName() + "complete inflate", Toast.LENGTH_SHORT).show();    }    /**     * View本身作为父View,当有子View添加进来时,由View本身回调该方法     *     * @param child     */    @Override    public void onViewAdded(View child) {        super.onViewAdded(child);        Toast.makeText(getContext(), getClass().getSimpleName() + "view added", Toast.LENGTH_SHORT).show();    }}


0 0