2013-01-06 120 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