在一个 ClickListener 中动态的添加一个视图
问题描述:
我想在 OnClickListener 的 RelativeLayout中添加一个视图:
montrolButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// myParent is a relative layout
// newChild is an ImageView
myParent.addView(newChild);
requestLayout();
}
});
我查看了 HierarchyViewer,但是没发现添加新的子类,哪里出错呢?
答
你可以这样:
RelativeLayout rv = (RelativeLayout) this.findViewById(R.id.right3);
ProgressBar iv = new ProgressBar(this);
rv.addView(iv);
答
要在Handler中进行添加