简体   繁体   English

Android如何从RelativeLayout移除ImageView

[英]Android How to Remove ImageView from RelativeLayout

I am trying to figure out what is the proper way to remove an ImageView from a RelativeLayout is? 我试图弄清楚从RelativeLayout中删除ImageView的正确方法是什么? I have tried 我试过了

relativeLayout.removeView(someImageView)

but this causes some issues on certain phones. 但这会导致某些手机出现问题。 See this other post here for stacktrace. 有关堆栈跟踪,请参见此处的其他文章。 Removing ImageView causes crash on certain phones 删除ImageView会导致某些手机崩溃

I really don't want to do the solution where you just make it appear gone because that is basically leaking that ImageView in memory right? 我真的不想做只是让它看起来消失的解决方案,因为这基本上是将ImageView泄漏到内存中,对吗?

someImageView.setVisibility(View.GONE);

Any other ideas would be much appreciated. 任何其他想法将不胜感激。

If you remove a view from a relative layout, you must reset the relative layout parameters for all other views which are dependent on the view that you are removing. 如果从相对布局中删除视图,则必须为所有其他视图(取决于要删除的视图)重置相对布局参数。 Otherwise, these other views will reference your removed view and throw a NPE. 否则,这些其他视图将引用您已删除的视图并抛出NPE。

Consider using another root layout design (like LinearLayout ) if you want to achieve this without using View.GONE 如果要在不使用View.GONE情况下实现此目的,请考虑使用其他根布局设计(例如LinearLayout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM