Code Droid
Code Droid

Reputation: 10472

How do I center and left justifiy hint text in EditText?

Here is my layout which does a good job of centering the hint, but how do I make the hint left justified with say a margin of 10dip ?, (ie I want to keep it centered vertically but also left justified)

             <EditText
                android:id="@+id/mobilePhoneNumber"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:inputType="number"
                android:ellipsize="start"
                android:gravity="center"
                android:layout_marginTop="10dip"
                android:hint="@string/lbl_hint_enter_mobile_phone_number"
                android:textSize="14dip"
                android:layout_marginLeft="10dip"
                android:layout_marginRight="10dip"
                android:maxLines="1" />

Upvotes: 3

Views: 11538

Answers (2)

LuxuryMode
LuxuryMode

Reputation: 33741

 <EditText
            android:id="@+id/mobilePhoneNumber"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ellipsize="start"
            android:gravity="left|center_vertical"
            android:paddingLeft="5dp"
            android:layout_marginTop="10dip"
            android:hint="hello world"
            android:textSize="14dip"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:maxLines="1" />

Upvotes: 12

xtr
xtr

Reputation: 5960

You need padding, not margin:

android:paddingLeft="10dip"
android:paddingRight="10dip"

and if you do not want center horizontal, set gravity to "center_vertical".

Upvotes: 3

Related Questions