图像按钮不显示

ImageButton not Showing

我首先尝试添加一个 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 里面,但是我的按钮没有出现,它显示如下:

我怎样才能让它出现?

你的imageButton显示不出来,因为EditText的宽度是match_parent,请改成[=15] =]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"
    />