Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

margin inside the edit text in android

My question is : I have an EditText and I want set a margin inside the EditText, I mean margin for the content (the text) of the edit text, not a margin for a the view witch I can resolve by this attribute : android:layout_marginLeft.

I need let some space before and after the text inside the EditText.

I tried to set the padding, but doesn't work !

this is my xml code :

<FrameLayout     android:layout_width="wrap_content"     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_height="wrap_content"      android:layout_marginLeft="2dp">      <EditText android:inputType="none"         android:textSize="15sp"          android:id="@+id/editText1"          android:scrollHorizontally="true"          android:layout_height="35dp"           android:padding="3dip"          android:singleLine="true"         android:layout_width="160dp"          android:layout_weight="0" />      <ImageView android:id="@+id/refreshButton"          android:src="@drawable/refresh"          android:layout_height="wrap_content"          android:layout_width="wrap_content"         android:layout_gravity="center_vertical|right" /> </FrameLayout> 

Can any one help me to do that?

Thanks in advance

like image 486
Alaoui Ghita Avatar asked Mar 28 '12 19:03

Alaoui Ghita


People also ask

How do you center text on android for editing?

To center align text in TextView in Kotlin Android, set android:textAlignment attribute with the value “center” in layout file, or programmatically set the textAlignment property of the TextView object with View. TEXT_ALIGNMENT_CENTER in activity file.

What is margin in android layout?

android:layout_marginTop Specifies extra space on the top side of this view. This space is outside this view's bounds. Margin values should be positive. May be a dimension value, which is a floating point number appended with a unit such as " 14.5sp ".


1 Answers

The padding variable should be exactly what you are looking for. You should try to increase the padding to something like 10dp just to test if it does anything. I'm guessing that because the background of the EditText is a 9 patch the padding is not acting how you would expect. When you set padding on a view with a 9 patch as the background any padding that is built into the 9 patch is than ignored. So if the 9 patch has 5dp padding and you set 3dp padding in the xml you will not get 8dp padding you will get 3dp.

like image 135
Bobbake4 Avatar answered Sep 28 '22 00:09

Bobbake4