gpt4 book ai didi

c# - 如何修复 Xamarin.Forms android 应用程序中的 Java.Lang.OutOfMemoryError?

转载 作者:行者123 更新时间:2023-11-30 04:59:07 26 4
gpt4 key购买 nike

所以,我的 Xamarin.Forms 应用程序有一些问题。当我尝试等待 ViewExtensions.LayoutTo 时出现“Java.Lang.OutOfMemoryError”。

我曾尝试将 Java 堆大小增加到 2G,但没有帮助。

public class SplashPage : ContentPage
{
public SplashPage()
{
NavigationPage.SetHasNavigationBar(this, false);

AbsoluteLayout layout = new AbsoluteLayout();
Content = layout;

Image image1 = new Image
{
Source = ImageSource.FromFile("image1.png"),
};
layout.Children.Add(image1);

Image image2 = new Image
{
Source = ImageSource.FromFile("image2.png"),
};
layout.Children.Add(image2);

Image image3 = new Image
{
Source = ImageSource.FromFile("image3.png"),
Scale = 0.5,
};
layout.Children.Add(image3);

layout.SizeChanged += async (s, e) =>
{
AbsoluteLayout.SetLayoutBounds(image1, new Rectangle(0, 0, image1.Width, image1.Height));
AbsoluteLayout.SetLayoutBounds(image2, new Rectangle(0, ((AbsoluteLayout)s).Height, image2.Width, image2.Height));
AbsoluteLayout.SetLayoutBounds(image3, new Rectangle(-image3.Width, ((AbsoluteLayout)s).Height - image3.Height - 5, image3.Width, image3.Height));

// I have placed those animations in SizeChanged event because i needed to get actual size of layout (outside this event it would be incorrect)
await ViewExtensions.LayoutTo(image2, new Rectangle(0, ((AbsoluteLayout)s).Height - image2.Height, image2.Width, image2.Height), 2300);
// here Java.Lang.OutOfMemoryError
await ViewExtensions.LayoutTo(image3, new Rectangle(((AbsoluteLayout)s).Width, ((AbsoluteLayout)s).Height - image3.Height - 5, image3.Width, image3.Height), 3000);

await Task.WhenAll(
image2.FadeTo(0, 700), image1.FadeTo(0, 700));

Application.Current.MainPage = new NavigationPage(new LoginPage());
};
}
}

最佳答案

尝试通过这种方式增加 AndroidManifest.xml 中应用的堆大小:

<application android:largeHeap="true"></application>

关于c# - 如何修复 Xamarin.Forms android 应用程序中的 Java.Lang.OutOfMemoryError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58542355/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com