android删除一个view中的子view

来源:互联网 发布:威风堂堂软件下载 编辑:程序博客网 时间:2024/06/10 22:20

android系统中已经提供了一些删除父控件中的方法。

如:.removeAllViews();
.removeViews(start, count);
.removeViewsInLayout(start, count);

....

但是有时这些并不是太满足需求,自己写删除子view的方法:

View view = null;(mContentLayout是父控件
for(int index = mContentLayout.getChildCount();index > 0;index --){
view = mContentLayout.getChildAt(index);
if(view != null && view instanceof RecyclerView){
} else {
mContentLayout.removeView(view);
}
}

注意:如果索引从index = 0开始删除的话,方法执行完之后,子view还存在,不能删除。(参考removeAllViews系统源码)


0 0
原创粉丝点击