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



所以,我的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>

相关内容

最新更新