【问题标题】:EditText - Gap between text and EditText's lineEditText - 文本和 EditText 行之间的间隙
【发布时间】:2015-01-22 05:17:03
【问题描述】:

当我在EditText 字段中插入文本时,文本本身与EditText 的行之间存在异常间隙。这是我终端的打印屏幕,您可以在其中看到我正在谈论的这个差距,它被标记为红色。

我尝试过文本对齐和重力,但没有成功。

这是 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>

有人能找出为什么会发生这种情况并解释我该如何解决吗?

--------------- 编辑 -----------

根据评论中的要求,我已将我在原始问题中发布的 XML 代码更新为我在我的应用上的真实 XML 代码。

第一个打印屏幕(上面的打印屏幕来自真实设备 -> 运行 Android 4.4.4 CyanogenMod 的 Galaxy S4),这里是使用 API 19 的模拟器的打印屏幕

【问题讨论】:

  • 那条绿线是自定义图片吗?
  • 不,这是EditText 的行,当您在其中输入一些文本时。
  • 它在我的最后工作正常..你是否为它添加了任何代码进行对齐?
  • 不,我没有。所有的布局代码都在那个xmlfile 上。奇怪的是它在你的设备上工作,因为在我的设备上它就像我在问题中发布的图片一样。
  • 这应该可以正常工作。这通常发生在 Android Studio 的模拟器/预览版中......实际上,它实际上并没有这样做。如果您可以访问其他设备,请在那里尝试

标签: android android-layout android-edittext android-xml


【解决方案1】:

要更改EditText 文本和底线之间的差距,您可以使用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"/>

根据您的要求替换 paddingBottom 值。或者你可以使用android:paddingTop

【讨论】:

  • 就我而言,增加android:paddingTop 是正确的方法。
【解决方案2】:

试试

android:layout_height="wrap_content"

而不是

android:layout_height="match_parent" 在您的 EditText 上。

【讨论】:

  • 不是我对你投了反对票,但我的EditText 都是android:layout_height="match_parent"
【解决方案3】:

尝试添加填充以编辑文本

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    • 2013-07-11
    • 2010-10-18
    • 1970-01-01
    • 2015-06-17
    • 1970-01-01
    相关资源
    最近更新 更多