[英]ImageView not showing up on Android
When I try to show an image using ImageView on my emulator, it shows up. 当我尝试在我的模拟器上使用ImageView显示图像时,它会显示出来。 Once I add a button, the image doesn't show up. 添加按钮后,图像不会显示。
I don't know if this helps, but my XML when it's working: 我不知道这是否有帮助,但我的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>
and not working: 而不是工作:
<?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>
Actually the problem is that you didn't define the orientation of LinearLayout.
实际上问题是你没有定义LinearLayout.
的方向LinearLayout.
By default it is horizontal, and you have set layout_width
of the button to fill_parent
, so it fills the whole area. 默认情况下它是水平的,并且您已将按钮的layout_width
设置为fill_parent
,因此它会填充整个区域。 You should either set the orientation to vertical or set android:layout_width="wrap_content"
in the button tag. 您应该将方向设置为垂直或在按钮标记中设置android:layout_width="wrap_content"
。
您需要做的就是将按钮' layout_width
为wrap_content
android:layout_width="wrap_content"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.