2013-01-06 54 views
1

使用它們可以使用的元素相對於其他元素進行對齊。Android對齊元素+相對於父元素的邊距

android:layout_alignLeft等。

但是如何添加餘量或一個填充:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="5dp" > 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:text="@string/students" 
     android:textSize="30sp" 
     android:typeface="normal" 
     android:layout_marginTop="10dp" 
     android:paddingTop="5dp" 
     android:paddingBottom="5dp" 
     android:id="@+id/student" />  

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@id/student" 
     android:paddingLeft="20dp" 
     android:paddingTop="30dp" 
     android:text="@string/stud_describe" 
     android:textSize="10sp" 
     android:textStyle="italic" 
     android:typeface="sans" /> 
</RelativeLayout> 

填充頂部的第二TextView不具有任何影響。

回答

1

看起來你正在填充和保證金混合起來。更改第二TextView到:的

layout_marginTop="30dp" 

代替

paddingTop="30dp". 

填充墊View本身,使其更大。保證金在其容器(RelativeLayout)內更改TextView的位置並且不會更改其大小。

+1

是的,添加填充將使b =填充在textview的頂部和文本的內部部分之間。而邊距將在文本視圖的頂部和其上方項目的底部之間留出空間。一個簡單的方法來看看你在做什麼時,要做的是給你的textview背景顏色。 – WallMobile