rdrmntn
rdrmntn

Reputation: 466

Text position in Android EditText

I have an issue when using EditText in my Android application. What I want is a large editable window where the user can start typing after an initial text in the top left corner (typing starts after the text). The issue is that the initial text is not printed in the top of the View.

When using a TextView it look like this, which is what I want:

TextView

But when changing to an EditText it look like this:

EditText

What property does set the text position? I've tried to change padding and paddingTop but none of them seem to make any difference. There is also a textAlignment which also does not do what I want.

Update: The properties:

    <EditText
    android:id="@+id/command_window_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_weight="0.33"
    android:background="@android:color/black"
    android:editable="true"
    android:fontFamily="monospace"
    android:padding="0dp"
    android:paddingStart="0dp"
    android:paddingTop="0dp"
    android:text="Example"
    android:textAlignment="viewStart"
    android:textColor="@android:color/holo_green_dark"
    android:textSize="14sp" />

Upvotes: 0

Views: 3337

Answers (4)

Use gravity="number"

In example :

<EditText
        android:id="@+id/simpleEditText"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:text="Please Ebter"
        android:gravity="2"
    />

enter image description here

Upvotes: 0

Raj
Raj

Reputation: 477

 <EditText
    android:id="@+id/command_window_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_weight="0.33"
    android:background="@android:color/black"
    android:editable="true"
    android:fontFamily="monospace"
    android:paddingTop="0dp"
    android:text="Example"
    android:lines="10"
    android:textAlignment="center"
    android:layout_below="@+id/card"
    android:textColor="@android:color/holo_green_dark"
    android:textSize="14sp" />

Upvotes: 1

ale.m
ale.m

Reputation: 883

Use gravity="top"

Example:

<EditText
    android:id="@+id/tv_weather_data"
    android:inputType="textMultiLine"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top"
    android:textSize="20sp" />

Upvotes: 0

Etrit Tahiri
Etrit Tahiri

Reputation: 38

Using android:gravity should work.

Upvotes: 2

Related Questions