Smolina Fezaphitsh
Smolina Fezaphitsh

Reputation: 347

android edit text how to start typing at the top left?

I have this EditText

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="textMultiLine"
        android:lines="5"
        android:singleLine="false"
        android:text="@string/app_name" />

</LinearLayout>

My problem is that typing starts at the middle of the EditText.

My question is how to start typing at the top left of the EditText?

Upvotes: 12

Views: 15076

Answers (3)

spyder man
spyder man

Reputation: 81

top|left will work, but for right-to-left locales android:gravity="top|start" is better.

Snippet of description of warning in IDE:

Using Gravity#LEFT and Gravity#RIGHT can lead to problems when a layout is rendered in locales where text flows from right to left. Use Gravity#START and Gravity#END instead. Similarly, in XML gravity and layout_gravity attributes, use start rather than left.

Upvotes: 0

be4code
be4code

Reputation: 698

I think it should work.

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="textMultiLine"
    android:lines="5"
    android:singleLine="false"
    android:gravity="top|left"
    android:text="@string/app_name" />

Upvotes: 5

William Kinaan
William Kinaan

Reputation: 28799

Try android:gravity="top" so your code will be :

<EditText
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:gravity="top"
     android:inputType="textMultiLine"
     android:lines="5"
     android:singleLine="false"
     android:text="@string/app_name" />

Upvotes: 26

Related Questions