EditText - Gap between text and EditText's line

邮差的信 提交于 2019-12-22 03:36:51

问题


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.

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


回答1:


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




回答2:


Try

android:layout_height="wrap_content"

instead of

android:layout_height="match_parent" on your EditText.




回答3:


Try adding padding to edit text

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:hint="Hint"/>


来源:https://stackoverflow.com/questions/28081704/edittext-gap-between-text-and-edittexts-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!