sad-ducky
sad-ducky

Reputation: 73

ImageView not showing up on Android

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" 
        android:layout_height="wrap_content"
        android:text="Back"/>
    <ImageView android:id="@+id/ImageView01"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent"/>
</LinearLayout>

Upvotes: 3

Views: 4942

Answers (2)

user782298
user782298

Reputation: 91

Everything you have to do is to make the buttons' layout_width to wrap_content

android:layout_width="wrap_content"

Upvotes: 0

Ashish
Ashish

Reputation: 1567

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.

Upvotes: 9

Related Questions