2011-11-27 102 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

相关问题