安卓框架提供了一種LinearLayout 內部佈局元素分割線的實現,創建一個指定長寬的矩形Shape:android
1 <?xml version="1.0" encoding="utf-8"?> 2 <shape xmlns:android="http://schemas.android.com/apk/res/android" 3 android:shape="rectangle"> 4 5 <size 6 android:width="@dimen/spacing_medium" 7 android:height="@dimen/spacing_medium" /> 8 9 <solid android:color="@android:color/transparent" /> 10 11 </shape>
做爲LinearLayout的Divider屬性引入:框架
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:layout_width="match_parent" 3 android:layout_height="wrap_content" 4 android:divider="@drawable/spacer_medium" 5 android:orientation="vertical" 6 android:padding="@dimen/spacing_medium" 7 android:showDividers="middle"> 8 9 <!-- TextView --> 10 11 <LinearLayout 12 android:id="@+id/buttons_container" 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" 15 android:divider="@drawable/spacer_medium" 16 android:orientation="horizontal" 17 android:showDividers="middle"> 18 19 <!-- Buttons --> 20 21 </LinearLayout> 22 23 </LinearLayout>