LinearLayout显示分割线(Divider)

来源:互联网 发布:spring源码 深度解析 编辑:程序博客网 时间:2024/04/30 09:43

Android LinearLayout显示分割线有两种方式:

1.使用一个宽/高为1dp的View:

<View    android:layout_width="match_parent"    android:layout_height="1dp"    android:background="#FF0000" />

2.直接使用LinearLayout的divider属性:


先做一个 Drawable:

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >    <size android:height="1dp"/>    <solid android:color="#FF0000"/></shape>
然后像这样使用:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:divider="@drawable/divider"    android:orientation="vertical"    android:showDividers="middle" >

后一种方法更推荐一些。

1 0
原创粉丝点击