Android上的ImageView未显示出来

3
当我在模拟器上使用ImageView尝试显示一张图片时,它能够正常显示。但是一旦我添加了一个按钮,图片就无法显示了。
我不知道这是否有帮助,但我的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>
2个回答

9

实际问题在于您没有定义LinearLayout的方向。默认情况下,它是水平的,并且您已将按钮的layout_width设置为fill_parent,因此它填充了整个区域。您应该将方向设置为垂直或在按钮标记中设置android:layout_width="wrap_content"


0

你需要做的就是将按钮的layout_width设置为wrap_content

android:layout_width="wrap_content"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接