[英]How to remove a view from a LinearLayout without affecting the positions of the other children?
I am trying to add/remove views to a LinearLayout inside a ScrollView. 我试图在ScrollView内的LinearLayout中添加/删除视图。 I would like to remove/add views to the LinearLayout while it is scrolling for larger lists might blow memory and/or be slow. 我想在LinearLayout滚动查看较大列表时将其删除/添加视图,这可能会消耗内存和/或速度很慢。 Is there any way to remove a View from the LinearLayout without it affecting the position of its siblings? 有什么方法可以在不影响其兄弟姐妹位置的情况下从LinearLayout中删除视图吗?
When I call linearLayout.removeChildAt(0)
, all of the views snap back one, making it really difficult to maintain a constant scrolling effect. 当我调用linearLayout.removeChildAt(0)
,所有视图都会回退一个,因此很难保持恒定的滚动效果。
我不确定这是否适合您(也许您已经意识到了这一点),但是通常当您必须显示一个视图列表时,您可以自己使用滚动视图和添加/删除子视图,而不用在Android中的ListView。
删除视图时,请使用与删除的视图相同大小的空白占位符视图替换它。
通过将位置0处已删除View的大小添加/减去到父级填充中,当我删除View时,我有效地停止了“斩波”效果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.