我有一个以编程方式膨胀的父自定义布局(LinearLayout 的子级)。
在构造函数中,我添加另一个布局作为父布局的子布局,如下所示:
public ExtendedContentLinearLayout(Context context) {
super(context);
this.context = context;
this.setClickable(false);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mTrigger = inflater.inflate(R.layout.nav_menu_board_expandable_children_outer, this, true);
mTrigger.setOnClickListener(this);
mTrigger.setBackgroundResource(R.color.da_blue);
}
父布局和“触发器”布局(上面刚刚添加的孩子)工作并显示正常。
一旦用户触摸了这个“触发”布局,我想向父级添加一个新子级 - 另一个包含更多内容的布局,因此我需要父级布局来扩展并包含新添加的布局,但这不起作用!
单击触发器布局不会添加新布局(至少未在屏幕上显示)。这是点击调用(点击事件正在工作):
@Override
public void onClick(View v) {
App.disableTouchEventForDefaultDuration();
Log.d("CLICKED", "CLICKED");
LinearLayout mContent = new LinearLayout(context);
mContent.setOrientation(HORIZONTAL);
mContent.setBackgroundResource(R.color.da_indicator_pink);
mContent.setVisibility(VISIBLE);
ExtendedContentLinearLayout.this.addView(mContent);
}