Android 自定义 LinearLayout

问题描述

我有点卡住了。我尝试创建自定义 LinearLayout 并使用其在 xml 文件中定义的子项。

    class MyRadioGroup @JvmOverloads constructor(
        context: Context,attrs: AttributeSet? = null,defStyleAttr: Int = 0
    ) : LinearLayout(context,attrs,defStyleAttr) {
    
        init {
           
            val c = childCount //always 0
            
        }
}

和使用我的类的 xml

<SomeViewGroup>
    <MyRadioGroup>
       <View/>
       <View/>
    </MyRadioGroup>
 </SomeViewGroup>

如何在 MyRadioGroup 中获取 xml 文件中定义的视图?

解决方法

嗯,问题是,什么时候班级会知道它的孩子。当我试图让孩子进入方法时

onfinishInflate

他们在那里