android - 将 TextView 左对齐到 EditText 中的文本?

标签 android android-layout alignment

我想将 TextView 中的文本与其正下方的 EditText 中的文本对齐。如果不使用填充技巧,这可能吗?

如果不是,是不是被气馁了?我可以看到它被劝阻,因为它可能会使用户感到困惑,从而忽略两个控件之间的区别。

enter image description here

这是创建上述屏幕截图的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/text_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="Please align my first character" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/text_view"
        android:hint="To my first character" />

</RelativeLayout>

最佳答案

不,如果不使用填充或 layout_margin,您将无法做到这一点。 EditText 有一个带边框和填充的背景,所以它的内容区域比 TextView 的区域小一点。我认为在这种情况下使用填充是正常的。

关于android - 将 TextView 左对齐到 EditText 中的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12644347/

相关文章:

java - 通过PATCH android发送参数

android - Proguard NoSuchMethodError I电话

android - 何时使用 Activity 转换与动态 fragment 的模式

android - 使用 Android 的 RecyclerView 时在滑动行下添加带有文本/图标的彩色背景

c++ - 数据对齐的差异

android - 使用 gradle 包含 butterknife 时重复文件

android - Firebase 数据的更改不会更新

android - 带有 android drawable xml 的光泽渐变

html - 如何将 flexbox 中一个元素的中心与另一个元素的基线对齐

php - 避免 fpdf 单元格中的重复项