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

时间:2014-06-22 11:50:03

标签: android android-view android-custom-view android-inflate

我有这个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。但它是空的。它在我稍后访问第一个孩子时起作用,例如,当我点击一个按钮时。我可以在何时访问自定义视图的子视图?

1 个答案:

答案 0 :(得分:1)

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

  

View.onFinishInflate()

是我正在寻找的。