如何将TextView左对齐到EditText内的文本?

4
我想将TextView中的文本与直接在其下方的EditText中的文本对齐。不使用填充技巧,是否有可能实现?
如果不行,是因为这样做被不鼓励吗?我认为不鼓励这样做,因为它可能会让用户忽略两个控件之间的区别。
以下是创建上述屏幕截图的布局:
<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>
3个回答

1
不行,你不能不使用填充或layout_margin来实现。 EditText具有带边框和填充的背景,因此其内容区域比TextView的区域略小。我认为在这种情况下使用填充是正常的。

0

我觉得你需要使用padding来调整TextView的位置。对我来说,TextView中的第一个字符和EditView中的第一个字符并不需要完全对齐。它们还有不同的字体大小,所以现在的样子看起来很自然 - 或者只需要稍微加一点padding就可以了,但不要太多。在添加padding时,请考虑到不同屏幕尺寸和分辨率的用户,因此请使用dp来进行android:layout_marginLeft的padding。例如:

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

希望这可以帮到你。


0

实际上这可能会让人感到困惑,但是您可以为TextView添加一点偏移量,使其看起来更好。使用android:layout_marginLeft并选择一个与您的要求相匹配的值。希望这有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接