2011-11-27 142 views
0

我寫了一個程序來測試MediaPlayer類,它有三個ImageButtons - 「播放」,「暫停」和「停止」。在開始時,我使用了三種不同尺寸的.png圖片作爲三個ImageButton,並且該程序無法在我的AVD上運行,然後我將它們更改爲三個具有相同大小的.png picutres,然後這次它正確運行。LinearLayout中的圖像是否必須具有相同的大小?

在LinearLayout中使用的圖像必須是相同的大小?

這裏是latyout文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" 
    /> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <ImageButton 
      android:id="@+id/play" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/play"> 
     </ImageButton> 
     <ImageButton 
      android:id="@+id/pause" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/pause"> 
     </ImageButton> 
     <ImageButton 
      android:id="@+id/stop" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/stop"> 
     </ImageButton> 
    </LinearLayout> 
</LinearLayout> 
+0

是否有一個原因,你爲什麼使用android:src而不是android:background? – josephus

+0

但它不是屬性的問題 – zenis

回答

0

我已經測試過你的代碼,但沒問題,但問題出在你刪除.png的圖像中,它會工作。酷,因爲.png已經在圖像中,你也可以在圖像中添加.png,以便從圖像中刪除.png。

+0

,你的意思是它們已經以PNG格式編碼,並且不需要命名他們是明確的.png ???但goodones.zip也被命名爲.png – zenis

+0

我認爲問題不在圖像goodones.zip如果你使用窗口去文件夾選項,並檢查隱藏藥水,這樣你可以看到不同。 –

+0

我沒有選擇該選項,所以我的圖像都命名爲xxx.png – zenis

0

確實在LinearLayout中的圖像使用必須是相同的大小?

否。wrap_content參數將使封裝的LinearLayout只與最大的ImageButton一樣大。

問題可能在於drawables的名稱。確保你的所有.png圖像遵循android命名約定(名稱只能包含小寫字母,數字0-9或下劃線)。

還檢查圖像本身沒有損壞。

+0

有沒有任何工具來檢查圖像是否可以在android程序中使用?我得到一個.png圖像形式的.jpg圖像,我所做的只是將.jpg的類型後綴修改爲.png – zenis

相關問題