Android ViewGroup.removeView() 不起作用
我通过扩展 ViewGroup 在我的项目中创建了一个小“小部件”。在该小部件中,我想添加和删除按钮(ImageView 的)。
创建小部件很容易并且添加按钮工作得很好,但有时当我想删除之前添加的按钮时,即使代码已被访问,它仍然显示在屏幕上。
小部件是通过布局 xml 添加的,我通过从活动中调用小部件中的函数来添加/删除按钮。 更准确地说;我的小部件获取 onClickEvent 并将其发送到我的活动,活动告诉我的小部件通过removeView() 删除按钮。
我已经尝试在小部件和按钮上使用 invalidate() 。我也尝试将其设置为不可见、布局(0,0,0,0)等,但没有任何效果。有人知道我做错了什么吗?
编辑:在下面的评论中回答
I have created a small "widget" in my project by extending a ViewGroup. In that widget I want to add and remove buttons (ImageView's).
It was easy to create the widget and adding buttons worked fine but sometimes when I want to remove a button I added earlier it's still displayed on the screen even though the code has been accessed.
The widget is added through the layout xml and I add/removes buttons by calling on a function in the widget from my activity.
To be more precise; my widget gets an onClickEvent and sends it to my activity who tells my widget to remove the button through removeView().
I have tried with invalidate() on both the widget and the button. I have also tried to set it to invisible, layout(0,0,0,0) and a few more but nothing is working. Anyone who got an idea what I'm doing wrong?
Edit: Answer in comment below
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论