动态添加和删除Android中的视图?如何TextView在Android应用程序中添加和删除s 等视图,例如在原始股票Android联系人屏幕上按下字段右侧的小图标,然后添加或删除由a TextView和a组成的字段editTextView(来自我可以看到)。关于如何实现这个的任何例子?
3 回答

不负相思意
TA贡献1777条经验 获得超10个赞
ViewParent
s一般不能删除视图,但ViewGroup
s可以。您需要将您的父级转换为ViewGroup
(如果是a ViewGroup
)以完成您想要的任务。
例如:
View namebar = View.findViewById(R.id.namebar);((ViewGroup) namebar.getParent()).removeView(namebar);
请注意,所有Layout
s都是ViewGroup
s。

哆啦的时光机
TA贡献1779条经验 获得超6个赞
这是我的一般方式:
View namebar = view.findViewById(R.id.namebar);ViewGroup parent = (ViewGroup) namebar.getParent();if (parent != null) { parent.removeView(namebar);}
- 3 回答
- 0 关注
- 1210 浏览
添加回答
举报
0/150
提交
取消