SuperIC社区_

标题: LinearLayout增加divider分割线 [打印本页]

作者: liuwei    时间: 2016-7-7 12:12
标题: LinearLayout增加divider分割线
在android3.0及后面的版本在LinearLayout里增加了个分割线
1
2
android:divider="@drawable/shape"
android:showDividers="middle|beginning|end"



分割线如果是图片那就直接使用图片就行,如果要使用颜色就必须使用shape来显示,直接使用颜色的id是没有用的 .可以使用argb。
android:divider="@color/black" 无效
android:divider="#000000" 有效
用颜色做分割线要设置高度




android:dividerHeight=1px

使用shape的时候要注意设置size属性不设置宽高分割线就不会显示出来,如果使用line那填充颜色只能使用stroke来显示颜色
使用例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

android:id="@+id/butt**_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@drawable/spacer_medium"
androidrientation="horizontal"
android:showDividers="middle"<

android:id="@+id/btn_first"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"

android:text="button_1"/<


android:id="@+id/btn_second"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"

android:text="button_2"/<


android:id="@+id/btn_third"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"

android:text="button_3"/<

</LinearLayout>



spacer_medium定义如下
1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<size
android:width="1dp"
android:height="107dp" />

<solid android:color="@color/black" />
</shape>




[img]file:///C:/Users/liuwei/AppData/Local/YNote/data/liuwei372**34@163.com/36d2dfdba324484ea86c8a3c9c9f3592/1420452529128101.jpg.jpeg[/img]
如果 android:showDividers="beginning",则是如下效果:
[img]file:///C:/Users/liuwei/AppData/Local/YNote/data/liuwei372**34@163.com/05f49251c46b4ac0be207bbd4f014e7e/1420452843288743.jpg.jpeg[/img]
但是不知为何android:showDividers="end"什么效果也没有。。。










欢迎光临 SuperIC社区_ (/) Powered by Discuz! X3.3