简体   繁体   English

如何使在滚动视图中(处于线性布局内)的视图无法创建?

[英]How to keep views in scrollview (that are inside a linear layout) that are not visible from being created?

I have linear layout inside a scrollview, and i would like to keep those views which are not visible(which are inside the linear layout) from being created until they are either visible or near to being visible. 我在scrollview中有线性布局,并且我想防止那些不可见的视图(在线性布局内部)被创建,直到它们变为可见或接近可见为止。 Like adjacent to one that is visible. 就像与可见的相邻。 I don't know if for example if turning off visibility will keep the View from being created(in terms of resources), or if gone could be used. 我不知道例如是否关闭可见性将阻止创建视图(就资源而言),或者是否可以使用它。

Update: The reason I am asking this question is because scrolling is taking a heck of a long time when there are say 30 view elements in the linear layout. 更新:我问这个问题的原因是因为当线性布局中有30个视图元素时,滚动花费了很长时间。 These are not large view elements either, about what you would find for a record in a listview. 这些也不是大视图元素,关于您将在列表视图中找到的记录。 I should add that the whole scrollview is inside a fragment. 我应该补充说,整个滚动视图都在一个片段内。

Thanks 谢谢

You have a LinearLayout(vertical) with 30 children. 您有一个带有30个子级的LinearLayout(vertical)。 If you scroll to the bottom, which views would then be "created"? 如果滚动到底部,那么将“创建”哪些视图?

  • If only the visible(or near visible) ones, then you can't measure how far down in the scroll they will be any more. 如果只有可见的(或接近可见的),那么您将无法测量滚动中向下的距离。

  • If at that point you're just saying you should create them when they first appear, and stay around afterward, that could work. 如果那时候您只是说您应该在它们初次出现时就创建它们,然后再保留它们,那可能会起作用。 However, once you scroll around some, you'll still have a bunch of views, and the same problem you have now. 但是,一旦滚动一些,您仍然会有很多视图,并且遇到了同样的问题。


Scrollviews exist and I happen to be using one. 滚动视图存在,我碰巧正在使用一个。

True, but that doesn't necessarily means it's the best tool for the job. 是的,但这并不一定意味着它是完成这项工作的最佳工具。 I tried something similar with my first Android project. 我在第一个Android项目中尝试了类似的方法。 I didn't know much about ListViews, and ended up rolling my own adapter that sounds eerily similar to what you're doing. 我对ListViews不太了解,最终推出了自己的适配器,听起来与您正在做的非常相似。

Long story short, the performance was bad. 长话短说,表现很差。 It did work, but once I(finally) switched to a ListView, the difference was nothing short of amazing. 确实有效,但是一旦我(最终)切换到ListView,区别就令人惊讶了。 I'm just trying to keep others from going down that road. 我只是想阻止其他人走这条路。 It was days of wasted time trying to get it "just right". 试图将其“正确”地浪费了几天的时间。

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

相关问题 以编程方式在(线性)布局内(即ScrollView内)添加Views - Programmatically add Views inside a (Linear)Layout (that is inside a ScrollView) 如何制作2个图像视图,每个视图的大小可以覆盖水平滚动视图内的线性布局内的屏幕 - How to make 2 images views each be sized to cover screen inside a linear layout inside a horizontal scrollview 如何正确放置视图以使所有视图在“线性布局”中可见? - How to put views properly to make all views visible inside Linear Layout? 滚动视图内部线性布局不滚动 - Scrollview inside linear layout not scrolling 滚动视图内的线性布局权重 - linear layout weight inside scrollview 线性布局内的线性布局正在添加但不可见 - linear layout inside linear layout is adding but is not visible 如何获取当前在回收站视图的线性布局中不可见的视图 - How to get the views which are not visible currently in the linear layout of the recycler view 在线性布局中按钮不可见 - Button not visible inside Linear Layout 如何在ScrollView内强制线性布局到屏幕底部? - How to force a Linear layout to the bottom of the screen while it's inside a ScrollView? 如何将可扩展列表视图和线性布局放入滚动视图 - How to put expandable listview and linear layout inside scrollview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM