方法一:
ViewGroup parent = (ViewGroup) .getParent(); if (parent != null) { parent.removeAllViews(); //或者 parent.removeView(view) } container.addView(view);
方法二:
View inflate = LayoutInflater.from(this).inflate(R.layout.view_empty_status, null, false); container.addView(view);
方法三:
View inflate = View.inflate(this, R.layout.view_empty_status, null); container.addView(view);
本文介绍了三种在Android中向容器视图添加子视图的方法。第一种方法通过获取父ViewGroup并调用removeAllViews或removeView来清空现有视图,然后调用addView添加新视图;第二种和第三种方法则是利用LayoutInflater来加载布局文件并将其添加到指定容器中。
2753

被折叠的 条评论
为什么被折叠?



