AlertDialog显示为空白

时间:2016-06-12 17:23:28

标签: c# xamarin.android alertdialog

我正在尝试打开一个在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();

3 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

问题在于drawable文件夹中的Image文件大小。图像的大小太大。当我尝试尺寸较小的图像时,它正在工作。