Android
Android

Reputation: 9023

How to put gap between Text and ImageView in EditText in android?

I am using the EditText with drawableLeft property and set ImageView in Right side for ClearText. My Question is how to put gap between text and Imageview in EditText?

Please help me.

Actually I have Like this,My Screenshot is, enter image description here

Actually I want to Like this, enter image description here

Create Gap Between Text and ImageView. How it is Possible?.

My xml file is,

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

        <EditText
            android:id="@+id/edtSearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_margin="5dip"
            android:drawableLeft="@drawable/search"
            android:drawablePadding="10dip"
            android:hint="Find"
            android:imeOptions="actionNext"
            android:inputType="text"
            android:singleLine="true" >
        </EditText>

        <ImageView
            android:id="@+id/imgSearchClear"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/edtSearch"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dip"
            android:contentDescription="@string/app_name"
            android:src="@drawable/clear" />
    </RelativeLayout>

Upvotes: 0

Views: 1247

Answers (5)

raj
raj

Reputation: 2088

i am using LinearLayout for this

 <LinearLayout
    android:id="@+id/linear"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:gravity="center"
    android:orientation="horizontal" >
 <EditText
        android:id="@+id/chatText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:inputType="textMultiLine"
        android:padding="8dp" />

    <ImageView
        android:id="@+id/buttonSend"
        android:layout_width="50sp"
        android:layout_height="50sp"
        android:padding="5dp"
        android:src="@drawable/ic_launcher" /> 
   </LinearLayout>

Upvotes: 1

Chingam Boy
Chingam Boy

Reputation: 46

Okay i got your Question now...you have to use Search view instead of edittext

Here is link:- Check it out

Only this is a solution of your problem

Upvotes: 2

Avinash Kumar Pankaj
Avinash Kumar Pankaj

Reputation: 1720

Set the right padding of EditText to the width of Clear button. Set all the dimension in dimen folder so that it will be compatible with all device sizes.

Upvotes: 0

Chingam Boy
Chingam Boy

Reputation: 46

Hello

Use Linear layout with weight instead of Relative as m showing below:-

<LinearLayout 
      width
      hight
      orientation="horizontal">

       <EditText
            android:id="@+id/edtSearch"
            android:layout_width="0dp"
             android:layout_weight="0.8"
            android:layout_height="wrap_content"

            android:layout_margin="5dip"
            android:drawableLeft="@drawable/search"
            android:drawablePadding="10dip"
            android:hint="Find"
            android:imeOptions="actionNext"
            android:inputType="text"
            android:singleLine="true" >
        </EditText>

        <ImageView
            android:id="@+id/imgSearchClear"
            android:layout_width="0dp"
             android:layout_weight="0.8"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dip"
            android:contentDescription="@string/app_name"
            android:src="@drawable/clear" />


       </LinearLayout>

if you found any issue regarding this please let me know..i love to help you

or in relative layou you can use drawable padding

Spartacus thanks :)

I can try to implement your code but It Like this,enter image description here

and I want to Like this,enter image description here

Upvotes: 0

Doppie
Doppie

Reputation: 95

Had the same problem a while ago fixed it with drawablePadding

Upvotes: 0

Related Questions