Home > database >  How do I start typing my description box in EditText from the top line in Android Studio?
How do I start typing my description box in EditText from the top line in Android Studio?

Time:06-02

I have added the picture to show that my current description box does not start from the first line when I start to type, how do I make it to start from the top left corner?

Description box not starting from top left corner

<EditText
    android:id="@ id/et_message"
    android:layout_width="350dp"
    android:layout_height="150dp"
    android:layout_marginLeft="25dp"
    android:layout_marginTop="390dp"
    android:background="@color/white"/>

I have added my xml code for the description box above.

CodePudding user response:

You should use android:gravity="start|top" in your EditText. for more details read here

<EditText
    android:id="@ id/et_message"
    android:layout_width="350dp"
    android:layout_height="150dp"
    android:layout_marginLeft="25dp"
    android:layout_marginTop="390dp"
    android:gravity="start|top"
    android:background="@color/white"
    android:text="@string/app_name"
    tools:ignore="MissingConstraints" />

CodePudding user response:

You should use android:gravity="" attribute in your edittext

The android:gravity attribute is used to arrange the position of the content inside your edittext

you can use below android:gravity as per your requirement

  • start
  • center
  • end
  • top
  • center_horizontal
  • center_vertical

Like this

<EditText
    android:id="@ id/et_message"
    android:layout_width="350dp"
    android:layout_height="150dp"
    android:layout_marginLeft="25dp"
    android:layout_marginTop="390dp"
    android:gravity="start"
    android:background="@color/white"/>

CodePudding user response:

below code may fit for your issue

<android.support.design.widget.TextInputLayout
      android:id="@ id/input_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="@dimen/spacing_small"
      app:counterEnabled="true"
      app:counterMaxLength="1000"
      app:counterOverflowTextAppearance="@style/TextLimitError"
      app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout"
      app:theme="@style/TextInputLayoutStyle">

                    <EditText
                        android:id="@ id/input"
                        style="@style/TextInputEditTextStyle"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="top|left"
                        android:hint="hint text"
                        android:inputType="textMultiLine"
                        android:lines="3"
                        android:maxLines="5"
                        android:minLines="3"
                        android:maxLength="1000"
                        android:singleLine="false"
                        android:scrollbars="vertical"/>
    </android.support.design.widget.TextInputLayout>

for more click here

CodePudding user response:

Use attribute android:gravity in your EditText and set it to "top". This will basically set your text to start from top of your EditText

  • Related