2012-09-28 118 views
4

我想將TextView中的文本與EditText內的文本對齊,該文本位於其正下方。這可能沒有使用填充技巧?將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> 

回答

1

不,您不能使用填充或layout_margin來做到這一點。 EditText具有邊框和填充的背景,因此其內容區域比TextView的區域略小。我認爲在這種情況下使用填充是正常的。

0

其實,這可能會造成混淆,但你可以加點偏移到TextView,使它看起來更好。使用android:layout_marginLeft並選擇一個符合您要求的值。希望這可以幫助。

0

我覺得你將不得不使用填充到TextView。對我來說,TextView中的第一個字符和EditView中的第一個字符並不完全對齊。它們也有不同的字體大小,所以它看起來很自然 - 或者只是一點點的填充,但不是太多。在填充時,不要忘記考慮具有不同屏幕尺寸和分辨率的用戶,因此請使用dp,並使用android:layout_marginLeft進行填充。例如:

<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" /> 

希望這會有所幫助。