2011-03-21 84 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