在 Xamarin.Forms 中向其子级添加视图时,有没有办法不重新加载整个 AnsoluteLayout?
当我希望在用户滚动时向其中添加新控件时,我使用 Xamarin.Forms AbsoluteLayout。为什么?因为在第一个页面打开时添加所有内容会花费很多时间,因为有很多项目。
我使用的是 AbsoluteLayout
,其 Children
是继承自 Layout
的自定义布局。在将控件添加到 Children
之前,我更新它们的 Bounds
属性,以便它们知道将自己放置在哪里。
看起来每次我调用 AbsoluteLayout.Children.Add()
时,所有现有的子项都会被测量和放置,也就是说,看起来会触发一个完整的布局周期。
有人知道如何绕过这个吗? (我已经尝试过CollectionView
,但是它在Android上有一个已知的抖动问题,所以我正在尝试寻找替代方案)。
非常感谢任何教育/信息。谢谢!
I am using a Xamarin.Forms AbsoluteLayout when I want new controls to be added to it when the user scrolls. Why? Because adding everything when the page 1st opens would take a lot of time since there are lots of items.
I am using an AbsoluteLayout
, whose Children
are custom layouts that inherit from Layout<View>
. Before I add the controls to the Children
I update their Bounds
property so that they know where to place themselves.
It looks like every time I call AbsoluteLayout.Children.Add()
, all the existing children are measured and places, that is, it looks like a full layout cycle is triggered.
Anyone knows how to bypass this? (I have tried CollectionView
, however it has a known issue of jitter on Android, so i am trying to find an alternative).
Any education/info is much appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,可以。基本上,有两种方法。
1.您可以创建一个异步方法来在后台线程上运行“内容/视图创建”,然后当您需要将该子视图添加到UI时,将其添加到主/UI线程上(BeginInvokeOnMainThread)。您可以参考对此链接。
2.您可以在 OnAppearing() 方法,该方法在页面变得可见之前,可以更快地呈现页面。
Yes,you can.Basically,there are two ways.
1.You can create an async method to run your "content/view creation" on a background thread and then when you need to add that child view to the UI, add it on the main/UI thread (BeginInvokeOnMainThread).You can refer to this link.
2.You can add views to its child in OnAppearing() method which is prior to the Page becoming visible that renders the page faster.