我正在创建自己的自定义 LinearLayout,并扩展它的类,我需要使用 addview 方法将子级添加到布局中,
我需要访问在构造函数之后设置的标签,所以我需要知道做这样的事情的最佳实践
这是我的代码:
public class MyLayout extends LinearLayout {
    public MyLayout(Context context) {
        super(context);
        MyTag tag = (MyTag) getTag();
        // Parent layout
        setOrientation(VERTICAL);
        setLayoutParams(new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.FILL_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        setBackgroundColor(tag.getBgColor());
    }
}