在 Xamarin.Forms 中向其子级添加视图时,有没有办法不重新加载整个 AnsoluteLayout?

发布于 2025-01-11 08:27:40 字数 502 浏览 0 评论 0原文

当我希望在用户滚动时向其中添加新控件时,我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2025-01-18 08:27:40

是的,可以。基本上,有两种方法。

1.您可以创建一个异步方法来在后台线程上运行“内容/视图创建”,然后当您需要将该子视图添加到UI时,将其添加到主/UI线程上(BeginInvokeOnMainThread)。您可以参考对此链接

2.您可以在 OnAppearing() 方法,该方法在页面变得可见之前,可以更快地呈现页面。

    protected override void OnAppearing()
    {
        base.OnAppearing();
        //add views to its child here
    }

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.

    protected override void OnAppearing()
    {
        base.OnAppearing();
        //add views to its child here
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文