Reputation: 205
I'm trying to add an ImageButton at first, and here is the XML that contains it:
<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>
This is inside another LinearLayout, but my button don't appear, it shows like this:
How can i make it appear?
Upvotes: 1
Views: 8509
Reputation: 1246
Your imageButton not show, because, the width of EditText is match_parent, please change it to wrap_content like this
<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"
/>
Upvotes: 4