2013-07-29 123 views
0

我的问题: 如何分隔两个组件?我已经将填充设置为2dp,但它们仍然在底部彼此连接,我如何将它们放在一起?到2dp。评论是值得赞赏的感谢在底部设置填充

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#d8d8d8" 
    android:orientation="vertical" 
    android:padding="2dp" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ff0043" 
     android:orientation="vertical" 
     android:padding="2dp" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="KELANA JAYA LINE" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="#fff" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#d8d8d8" 
     android:orientation="horizontal" 
     android:paddingRight="2dp" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="74dp" 
      android:layout_height="wrap_content" 
      android:background="#001eff" 
      android:paddingRight="2dp" 
      android:text="TIME" 
      android:textColor="#fff" 
      android:textSize="20dp" 
      android:textStyle="bold" /> 

    </LinearLayout> 

</LinearLayout> 

回答

0

填充是视图边界“内部”的空间,它不是强制要求视图尊重它,虽然系统视图执行它(至少大部分)。

要分开两个视图使用layout_margin。

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ff0043" 
     android:orientation="vertical" 
     android:layout_margin="2dp" > 
    <TextView /> 
</LinearLayout> 

android:padding="2dp" 

通过

android:layout_margin="2dp" 
变化
1

尝试margin(left,right,top,bottom)属性,而不是

0

这是因为,您使用的是线性布局和填充只为组件的内部部件。(里面的文字,你的情况) 。为什么不使用相对布局,以便您可以将组件放在任何地方?