ImageButton没有显示

时间:2015-12-28 00:14:20

标签: android android-imagebutton

我首先尝试添加一个ImageButton,这里是包含它的XML:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_alignParentTop="true"
    android:id="@+id/name_search_layout"
    android:background="@android:color/darker_gray"
   >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/label_name"
        android:text="@string/name_label"
        android:textSize="20sp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:textStyle="bold" />


    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/text_name"
        android:hint="@string/name_hint"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"/>

    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button_expand"
        android:layout_gravity="right"
        android:src="@android:drawable/btn_plus"
        />
</LinearLayout>

这是在另一个LinearLayout中,但我的按钮没有出现,它显示如下:

The button is circulated in blue

如何让它出现?

1 个答案:

答案 0 :(得分:3)

您的imageButton未显示,因为 EditText 的宽度为 match_parent ,请将其更改为 wrap_content ,如下所示

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:id="@+id/name_search_layout"
android:background="@android:color/darker_gray">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/label_name"
    android:text="@string/name_label"
    android:textSize="20sp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:textStyle="bold" />


<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/text_name"
    android:hint="@string/name_hint"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"/>

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/button_expand"
    android:layout_gravity="right"
    android:src="@android:drawable/btn_plus"
    />

相关问题