我可以在自定义视图中访问xml定义的子视图的最早时间是什么

古老的

我有这个xml文件:

<my.CustomView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ff0000"/>
</my.CustomView>

和这个对应的类:

public class CustomView extends LinearLayout {

    private View mSubview;

    public CustomView(Context context, AttributeSet attrs) {
        super(context, attrs);

        mSubview = getChildAt(0);
    }
}

在构造函数中,第一个孩子应该分配给mSubview。但是,它为空。当我稍后访问第一个孩子时(例如,当我单击按钮时),它可以工作。在什么时候可以访问自定义视图的子视图?

古老的

我应该更仔细地阅读文档...

View.onFinishInflate()

是我一直在寻找的东西。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章