0

带有自定义视图组和子视图的 some_layout.xml

<com.github.espiandev.showcaseview.ShowcaseView
        xmlns:android="http://schemas.android.com/apk/res/android"
        style="@style/ShowcaseView">
    <include
        layout="@layout/showcase_button"
        android:id="@id/showcase_button"/>
</com.github.espiandev.showcaseview.ShowcaseView>

ShowcaseView.java - 我什么时候可以访问自定义视图组中的 R.id.showcase_button

private Button mEndButton;

public ShowcaseView(Context context) {
    this(context, null, R.styleable.CustomTheme_showcaseViewStyle);
}

public ShowcaseView(Context context, AttributeSet attrs) {
    this(context, attrs, R.styleable.CustomTheme_showcaseViewStyle);
}

public ShowcaseView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    // cannot be found at this stage, returns null
    mEndButton = (Button) findViewById(R.id.showcase_button);
}

我应该覆盖什么 View 或 ViewGroup 方法,或者我应该观察什么事件?

  • 在 Activity 中,视图在 setContentView 之后变得可用,但是从 XML 文件构造的自定义视图的生命周期是什么?
  • findViewById(R.id.showcase_button) 最早会成功的点是什么,以便分配字段?
4

0 回答 0