android中设置分隔线几种方法

作者: 创客乌托邦 | 来源:发表于2017-08-22 21:41 被阅读166次

    方法一

    也是我们常用的方法,可以在按钮间添加作为分割线的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">

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

    相关文章

      网友评论

        本文标题:android中设置分隔线几种方法

        本文链接:https://www.haomeiwen.com/subject/hdkrdxtx.html