【发布时间】: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