Reputation: 2435
My goal is to display a couple of buttons and then a PNG image. The problem is that the image doesn't display at all. If I take out all the buttons, then the Image will display. What exactly is wrong with this xml file?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:adjustViewBounds="true"
tools:context=".MainActivity" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/option1"
android:onClick="sendMessage" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/OR" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/option2"
android:onClick="sendMessage" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/Pic"
android:src="@drawable/soup" />
</LinearLayout>
Upvotes: 1
Views: 2380
Reputation: 126
There is nothing wrong. As you are using "wrap_content" for individual views , you are probably crossing the layout bounds. You can set layout weights in this case to fit all.
Upvotes: 0
Reputation: 38595
LinearLayout will lay out each child until it runs out of space. The ImageView won't be on screen if the first three children take at least as much space as the width of the screen (I say width because LinearLayouts are horizontal by default -- if you intended it to be vertical, you must include the android:orientation="vertical"
attribute).
You either need to specify layout weights to give each chid a certain portion of the available space, or you need to choose another layout that better suits your needs.
Upvotes: 2
Reputation: 2470
Set your linearlayout with "android:orientation" to horizontal or vertical. That might fix it.
Upvotes: 0