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

标签 c# android xamarin.forms

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

相关文章:

c# - 在 EntityDataSource 中使用参数化的 LIKE 子句

c# - BigInteger 中的 .NET 错误?

c# - Amazon Api 升级好像去掉了一些方法?

java - 完整的 native 应用程序仍然需要 root 访问权限吗?

xamarin - OnAppearing 在 iOS 和 Android 上不同

c# - 在连接 Sql Server 数据库时,Java 和 C# 有什么区别?

java - 圆弦的最佳方法

java - 解析增量功能的增量不会超过 1

c# - 如何在 xamarin 表单中为 ListView 的每个项目提供不同的文本颜色

c# - ActivityIndi​​cator 未在绑定(bind)到 ViewModel 的 XAML 中显示