給 LinearLayout 新增分割線 divider
阿新 • • 發佈:2018-12-27
給佈局新增分割線,就像這種,具體做法:
推薦方法:
LinearLayout有兩個屬性:
1、divider
android:divider = ""
- divider可以是圖片檔案,也可以是xml繪製的shape。
- 使用shape的時候一定要新增
<size>
,一定要新增color
,即使是透明也要寫上
例如:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/black" /> <size android:height="1px" /> </shape>
2、showDividers
android:showDividers = "middle|end|beginning|none"
- middle 在每一項中間新增分割線
- end 在整體的最後一項新增分割線
- beginning 在整體的最上方新增分割線
- none 無
整體的寫法就是這樣:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:divider="@drawable/divider" android:showDividers="middle"> </LinearLayout>
文章來源於 https://blog.csdn.net/fengyeNom1/article/details/85244364