【发布时间】:2017-02-24 02:34:15
【问题描述】:
我做膨胀布局。我想在布局中的每个项目之间给出间距。如下图所示
这是我在 xml 中的主要代码。父布局
<LinearLayout
android:id="@+id/mLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#F2F2F2"
android:orientation="vertical"
android:padding="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="wrap_content"
android:orientation="horizontal"
android:padding="3dp"
android:layout_marginTop="5dp"
android:background="@color/white_pure">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:orientation="vertical">
<TextView
android:textStyle="bold"
android:textSize="12sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"/>
<TextView
android:layout_width="wrap_content"
android:textSize="9sp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"/>
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="right"
android:layout_marginRight="5dp"
android:textColor="@color/blueTransfer"/>
</LinearLayout>
我怎样才能得到像图像(左侧)。在膨胀布局中的每个项目之间有间距。希望任何人都可以帮助我。
【问题讨论】:
-
使用边距而不是内边距。然后,为每个部分设置背景白色和灰色。
-
怎么样?我想我已经为每个布局设置了边距。呵呵
-
能否提供完整的每个项目视图xml?
标签: android layout spacing android-inflate