LinearLayout 分割线

来源:互联网 发布:tomcat端口配置文件 编辑:程序博客网 时间:2024/04/30 12:39

这里写图片描述

像这种情况,在一个linearlayout中用分割线将内部的item分割开,以前我做的方式特别傻:二个分割线中间夹一个1dp的ImageView(不知道大家有没有这么做的),现在终于找到简单的办法了,代码如下:

<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" >

关键在于这二行代码:

android:divider="@drawable/divider"android:showDividers="middle"

接下来我看看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="#000000"/></shape>

注意:

 1.android.support.v7.widget.LinearLayoutCompat          我试过这个控件是不支持以上代码的。这点大家要注意。 2.showDividers:可取值为:middle(子元素间)、beginning(第一个元素左边)、end(最后一个元素右边)、none; 3.dividerPadding:设置绘制间隔元素的上下padding。

结尾

写出来对自己加深印象,如果能对大家有帮助,我很高兴。

0 0
原创粉丝点击