1

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>
4

3 回答 3

2

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.

于 2013-07-25T02:17:10.183 回答
0

没有任何错误。当您对单个视图使用“wrap_content”时,您可能正在跨越布局界限。在这种情况下,您可以设置布局权重以适合所有人。

于 2013-07-25T02:22:56.710 回答
0

Set your linearlayout with "android:orientation" to horizontal or vertical. That might fix it.

于 2013-07-25T02:16:07.890 回答