简体   繁体   English

在LinearLayout中重用Android视图

[英]Reusing Android views in a LinearLayout

I'm making sort of a news feed, that is displayed below a static menu. 我正在整理一个新闻提要,该提要显示在静态菜单下。 To avoid the news feed from being scrolled in the tiny bit of space that's left after the menu, I wanted to scroll both the menu and the newsfeed at the same time. 为了避免新闻提要在菜单后剩余的一小部分空间中滚动,我想同时滚动菜单和新闻提要。

Now I'm realizing this with a LinearLayout, so it doesn't scroll itself like the listview. 现在,我通过LinearLayout实现此功能,因此它不会像listview一样滚动自身。 But my question is, is using a LinearLayout, which from what I know doesn't reuse views like a listView, bad practice? 但是我的问题是,使用的是LinearLayout,据我所知,它不会像listView那样重用视图,这是不好的做法? How likely am I to get into memory issues, since the news feed can have A LOT of views, and they all contain images. 由于新闻提要可以有很多视图,而且它们都包含图像,因此我有多大可能陷入内存问题。

Many thanks! 非常感谢!

Apparently there is a pretty good chance for you to get an OutOfmemmoryexception in no time with this approach,If you want to go with re-using the views 显然,如果您想重新使用视图,那么您很有可能立即获得OutOfmemmoryexception

I suggest you should go with the new RecyclerView s in Android, Go here for a tutorial on recycler views 我建议您应该使用Android中新的RecyclerView在这里获得有关RecyclerView视图的教程

I don't know if this qualifies to be an answer. 我不知道这是否符合答案。 But if you are using a LinearLayout with a header view and a ListView inside it, then there are no issues. 但是,如果您使用的是带有标题视图和其中的ListViewLinearLayout ,则没有问题。 Since the main worry you have is the news feed which would be recycled by the ListView . 由于您主要担心的是新闻提要,该提要将由ListView回收。 Neglecting to use view recycling is asking for trouble, and will likely break after 50 or so (Android hates images). 忽略使用视图回收会带来麻烦,并且可能在50次左右后中断(Android讨厌图像)。

As for the header that must disappear. 至于必须消失的标题。 I would avoid putting it as the first item in a ListView as suggested in the comments, and rather have it static in the LinearLayout . 我会避免将其作为注释中建议的ListView的第一项放置,而是将其在LinearLayout静态。 And use a view translation and/or transparency to hide it. 并使用视图转换和/或透明度将其隐藏。 This keeps the option availible to display the header at any point, regardless of the list's scroll. 这样,无论列表滚动如何,该选项都可用于随时显示标题。

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

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