0

I would like to align 3 buttons inside edittext and found this on SO but I'm unable to align them in a proper way.

This is what I have:

 <RelativeLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/additems"
        android:singleLine="true"
        android:lines="1"
        android:maxLines="1"
        android:scrollHorizontally="true"
        android:ellipsize="end"
        android:layout_weight="1"
        android:hint="Add Item" 
        android:padding="15dp"
        android:background="@drawable/group_top"/>

  <Button
        android:id="@+id/search"
        android:padding="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/additems"
        android:layout_alignBottom="@+id/additems"
        android:layout_alignRight="@+id/additems"
        android:src="@drawable/search" />
  <Button
        android:id="@+id/microphone"
        android:padding="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/additems"
        android:layout_alignBottom="@+id/additems"
        android:layout_alignLeft="@+id/search"
        android:src="@drawable/microphone" 
        android:layout_marginLeft="-40dp"/>

</RelativeLayout>

As you can see in the above layout for "microphone" I'm using margin left with -40dp and padding is also difference from search button..Is it the correct way of doing this or it may show different in various screens? Can anyone suggest me the best design for this ?

Community
  • 1
  • 1
coder
  • 13,002
  • 31
  • 112
  • 214

1 Answers1

0

You need to create LinearLayout with background like EditText. Then put inside EditText with transparent background and all others Views you want. In this case layout_gravity can help you.

QArea
  • 4,955
  • 1
  • 12
  • 22