AlertDialog 显示为空白

AlertDialog is shown blank

我正在尝试打开一个在 AlertDialog 中有图像的布局。但是我得到一个空白对话框。这是我的代码。

ImageView.axml布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="350dp"
        android:id="@+id/imageView"
        android:src="@drawable/Apple"
        android:scaleType="centerInside" />
</LinearLayout>

C#代码:

 AlertDialog.Builder builder = new AlertDialog.Builder(this);
 AlertDialog dialog = builder.Create();
 LayoutInflater inflater = LayoutInflater.From(this);
 View dialogLayout = inflater.Inflate(Resource.Layout.ImageView, null);
 dialog.SetView(dialogLayout);
 dialog.Show();

根据this tutorial,create()在设置View之后被调用。我知道出于习惯,我总是调用 create() 然后最后调用 show()。希望对您有所帮助。

我只是 运行 你的代码使用最新版本的 Xamarin,我可以在对话框中看到图像。所以,我敢打赌您的 Resources/drawable 文件夹中没有 "Apple.png" 图像文件。如果这样做,请尝试另一个 png 文件 and/or 确保该图像的 "BuildAction" 设置为 "AndroidResource".

此外,可绘制资源应全部小写。

问题与可绘制文件夹中的图像文件大小有关。图片尺寸太大。当我尝试使用较小尺寸的图像时,它起作用了。