2011-03-21 81 views
3

當我嘗試在模擬器上使用ImageView顯示圖像時,它顯示出來。 一旦我添加一個按鈕,圖像不顯示。ImageView未顯示在Android上

我不知道這是否會有所幫助,但我的XML時,它的工作:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <ImageView android:id="@+id/ImageView01" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent"/> 
</LinearLayout> 

和不工作:你必須做

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <Button 
     android:id="@+id/backbutton" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Back"/> 
    <ImageView android:id="@+id/ImageView01" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent"/> 
</LinearLayout> 

回答

9

其實問題在於你沒有定義LinearLayout.的方向默認情況下它是水平的,並且您已將按鈕的layout_width設置爲fill_parent,因此它填充整個區域。您應該將方向設置爲垂直或在按鈕標記中設置android:layout_width="wrap_content"

0

的一切都是要讓按鈕layout_widthwrap_content

android:layout_width="wrap_content" 
+0

哦好吧謝謝! – 2011-03-21 05:30:05