android中设置分隔线几种方法

方法一

也是我们常用的方法,可以在按钮间添加作为分割线的View,设定好View的宽度高度和颜色值后插入按钮的布局间。

View的样式如下:

android:layout_height="fill_parent"

android:layout_width="1dp"

android:background="#90909090"

android:layout_marginBottom="5dp"

android:layout_marginTop="5dp"

/>

方法二

通过LinearLayout指定的divider的属性来插入分隔符,类似于Listview的效果。这种方法的好处在于缩减布局代码量,同时在button数量未知的情况下能更方便的进行显示。但是这种方法只适用API版本11以上的机型。

使用方法也很简单,先创建分隔线的样式文件


<?xml version="1.0" encoding="utf-8?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

<size android:width="1dp">

<solid android:color="#90909090"/></shape>

再在布局文件中引用

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:adjustViewBounds="true"

android:divider="@drawable/separator"

android:showDividers ="middle|end|beginning|none">

android:orientation="horizontal">

分隔线的样式也可以用图片来替代,这就看项目的需求了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容