EditText - Gap between text and EditText's line

dazito picture dazito · Jan 22, 2015 · Viewed 21.7k times · Source

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

Answer

Kishan Vaghela picture Kishan Vaghela · Dec 29, 2015

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