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

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

    原文作者:文武大侠
    原文地址: https://www.jianshu.com/p/e43b40acf0d8
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞