android中设置分隔线几种方法
16lz
2021-01-23
方法一
也是我们常用的方法,可以在按钮间添加作为分割线的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?>
再在布局文件中引用
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 使用DigestUtilsmd5加密的方法
- 善用Android预定义样式
- android布局属性之margin
- Android 新手入门(2)-界面布局
- android布局 LinearLayout和RelativeLayout
- Android预定义样式