When I try to show an image using ImageView on my emulator, it shows up. 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 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"
a开发者_开发百科ndroid: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.
By default it is horizontal, and you have set layout_width
of the button to fill_parent
, so it fills the whole area. You should either set the orientation to vertical or set android:layout_width="wrap_content"
in the button tag.
Everything you have to do is to make the buttons' layout_width
to wrap_content
android:layout_width="wrap_content"
精彩评论