- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的布局中有以下层次结构:
ScrollView
RadioGroup
RelativeLayout
RadioButton
ImageView
RelativeLayout
RadioButton
ImageView
...
现在的重点是,它在 XML 编辑器中看起来不错,其中 RadioButtons
和 ImageViews
定义了默认值(占位符),但是当我启动一个 Activity 并调用RadioGroup
上的removeAllViews()
,所有ImageViews
都消失了。有趣的是,所有按钮都获得了新值,只有 ImageViews
没有更新(设置新的源图像没有结果)。
所以,我的问题是:removeAllViews()
是完全删除 subview (就像它们从未存在于布局 XML 文件中一样)还是只是删除一些值,留下要定义的 View 参数(比如设置新的源图像或新的按钮描述)?
最佳答案
来自official documentation , removeAllViews()
:
Call this method to remove all child views from the ViewGroup.
调用此方法会将所有 subview 设置为null
,因此它将从自身中删除 subview ,并且此 subview 变为无效(或不被视为子),但不像它在 XML 文件中从未存在过。
public void removeAllViews() {
removeAllViewsInLayout();
requestLayout();
invalidate();
}
正如您在 removeAllViewsInLayout() 中看到的那样方法,它将子值设置为空:
children[i] = null;
关于android - removeAllViews() 对 subview 有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29926008/
我正在制作一个简单的提醒应用程序。 当我关闭第二个使用 SharedPreferences 添加新任务的 Activity 时,就会出现问题,并且在此操作之前没有任何任务 (count_of_task
我有一个类,其中我在单击按钮时包含另一个布局。这个包含的布局有一些按钮和点击这些按钮时执行的代码。我使用了一个计数器来指示单击按钮的次数。第一次单击按钮包括布局,第二次单击删除 View 等。这是代码
我尝试删除线性布局的所有 subview ,但没有删除任何内容,奇怪的是相同的代码正在另一个应用程序中工作。 Here's the sample code of the method that pop
我在我的代码中遇到了 OutOfMemory 异常,所以我正在审查代码。 我有一个问题,View.removeAllViews() 是否会释放之前添加到该父 View 中的 subview 所使用的内
我的布局中有以下层次结构: ScrollView RadioGroup RelativeLayout RadioButton I
我对 removeAllViews 和 setContentView 有问题..... 两者都不适合我,我不知道为什么。我在一个返回 View 的类中有一个函数,我想将该 View 添加到屏幕上,并且
我正在动态填充线性布局。根据响应,我必须清除过去的 subview 并创建新 View 。我已经阅读了文档,但仍然对这几种方法感到困惑,它们看起来都具有相同的功能。我应该使用哪个函数。 最佳答案 正如
一些背景:我在构建“编辑数据库” View 然后再次删除行的程序部分遇到问题。每次显示“编辑数据库” View 时显示的字段都不同。编辑数据库 View 是一个表格布局,数据库中的每一行都是表格布局中
我有一个动态创建的 com.google.android.gms.maps.MapView,使用 mapView = new MapView(DataManager.getInstance().get
我是一名优秀的程序员,十分优秀!