2016-06-12 65 views
1

我試圖打開一個佈局,其中有一個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(); 

回答

0

問題在於可繪製文件夾中的圖像文件大小。圖像的大小太大了。當我嘗試使用較小尺寸的圖像時,它正在工作。

+0

較小的圖像文件名全部是小寫嗎?如果是這樣,我會嘗試將「Apple.png」重命名爲「apple.png」(並相應地更新「src =」條目),並將其重新命名爲drawable資源文件名應該是小寫的(如果不是,則會遇到問題,如GetIdentifier()返回一個零)。我也用這個建議更新了我的答案。 –

0

this tutorial,create()時設置查看後調用。我知道出於習慣,我總是調用create(),然後show()繼續。希望有所幫助。

1

我剛剛使用最新版本的Xamarin運行了您的代碼,我可以在對話框中看到圖像。所以,我打賭你的資源/可繪製文件夾中沒有「Apple.png」圖像文件。如果你這樣做,嘗試另一個PNG文件和/或確保該圖像的「BuildAction」設置爲「AndroidResource」。

另外,可繪製的資源應該全部小寫。