Android: align text in edittext

I am creating an application in which I have to use edit text, and when I use this text on samsung s galaxies and the emulator, the text starts from the center of the edittext, not the top. The screen and code are as follows `

<EditText android:id="@+id/tester" android:layout_height="113dip" android:layout_width="420dip" android:background="@drawable/textarea_reason" android:paddingTop="-90dip"/> 

When i enter the text in edit text it starts from some gap rather than starting from top `

+4
source share
4 answers

You need to change the gravity parameter.

Java code

 editText.setGravity(Gravity.TOP| Gravity.LEFT); 

XML

 <EditText android:id="@+id/tester" android:layout_height="113dip" android:layout_width="420dip" android:background="@drawable/textarea_reason" android:gravity="top|left"/> 
+12
source

Refresh yor Change text tag as ...

 <EditText android:id="@+id/tester" android:layout_height="113dip" android:layout_width="420dip" android:background="@drawable/textarea_reason" android:gravity="top|left"/> 
+5
source

You installed the reverse source image, so the problem occurs android: paddingLeft = "20dp" and test

0
source

Try editing text properties singleLine="false" in xml or minLines to> 1

0
source

Source: https://habr.com/ru/post/1384297/


All Articles