简体   繁体   English

如何从LinearLayout中删除视图而不影响其他子项的位置?

[英]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.

相关问题 Android:如何从另一个 class 的线性布局中删除视图? - Android: How to remove view from linearlayout from another class? 如何从父线性布局中删除返回列表视图? - How to remove return list view from parent linearlayout? 如何在不影响其他组件的情况下重新绘制组件 - How to repaint a component without affecting other components 如何按位置从 LinearLayout 中删除图像视图 - How to remove a imageview from a LinearLayout by position 如何在ListView中控制LinearLayout的子级? - How to control children of LinearLayout in a ListView? 如何从 android textview(多行)中删除一个单词而不影响其他单词的对齐/位置 - How to delete one word from a android textview (multiple lines) without affecting the alignment/position of other words 如何永久删除线性布局? - How to permanently remove a linearlayout? 如何在不影响其他表列的情况下调整单个JTable列的大小 - How to resize a single JTable column without affecting the other table columns 如何在不影响其他活动性能的情况下在后台下载文件列表? - How to download a list of files in background without affecting the performance of other activities? 如何在不影响其他集合的情况下编写联合方法? - How do I write a union method without affecting the other sets?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM