我的问题: 如何将两个组件分开?我已将所有侧面的填充设置为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 :(得分:1)
尝试使用margin(left,right,top,bottom)
属性
答案 1 :(得分:0)
这是因为,您使用的是线性布局,并且填充仅适用于组件内部的组件。(您的案例中的文本内部)。为什么不使用相对布局,以便可以将组件放在任何地方?
答案 2 :(得分: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"