Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText - Gap between text and EditText's line

When I insert text to my EditText field the text has an abnormal gap between itself and the EditText's line. Here's a printscreen from my terminal where you can see this gap I'm talking about, it is marked in red. enter image description here

I've played around with text alignment and gravity but to no success.

Here's the XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                tools:context=".MainActivity">

    <TableLayout
        android:id="@+id/startJourneyLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1">

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <TextView
                android:id="@+id/startLocationTxtView"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_column="0"
                android:layout_gravity="start"
                android:text="@string/startLocation"
                android:gravity="center"
                android:textAppearance="?android:attr/textAppearanceLarge"/>

            <EditText
                android:id="@+id/startLocation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:gravity = "bottom"
                android:hint="Some text"
                android:inputType="text"/>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_column="2"
                android:src="@drawable/my_ic_location"/>
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <TextView
                android:id="@+id/endLocationTxtView"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_column="0"
                android:layout_gravity="start"
                android:gravity="center"
                android:text="@string/endLocation"
                android:textAppearance="?android:attr/textAppearanceLarge"/>

            <EditText
                android:id="@+id/endLocation"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_column="1"
                android:inputType="text"/>
        </TableRow>

        <Button
            android:id="@+id/goButton"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:text="@string/go"/>

    </TableLayout>

</RelativeLayout>

Can someone spot why this is happening and explain me how can I fix it?

--------------- EDIT -----------------------

I've updated the XML code I posted in the original question to the real XML code I've on my app as requested in a comment.

The first printscreen (the one above, is from a real device -> Galaxy S4 running Android 4.4.4 CyanogenMod) and here is a printscreen from the emulator using API 19

enter image description here

like image 624
dazito Avatar asked Jan 22 '15 05:01

dazito


People also ask

How do I show errors in EditText?

You can use the TextInputLayout to display error messages according to the material design guidelines using the setError and setErrorEnabled methods. In order to show the error below the EditText use: TextInputLayout til = (TextInputLayout) findViewById(R. id.

How do you center text in EditText?

Simpler Solution to align text in EditText is to add android:gravity="center" in layout xml. There is no need to add Java code.


Video Answer


1 Answers

To change gap between EditText text and bottom line you can use android:paddingBottom

<EditText
     android:id="@+id/nameEditText"
     style="@style/DarkEditText"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:hint="@string/name"
     android:paddingBottom="20dp"/>

Replace paddingBottom value as per your requirement. Or you can use android:paddingTop

like image 179
Kishan Vaghela Avatar answered Sep 21 '22 09:09

Kishan Vaghela