用LinearLayout添加的分割线

divider.png

1.Create divider shape(创建shape)

//shape divider_horizontal.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
 
    <size android:width="@dimen/divider_width"/>
    <solid android:color="@color/colorPrimaryDark"/>
 
</shape>

2.Add shape to LinearLayout

<LinearLayout android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:background="@android:color/white"
              android:divider="@drawable/divider_horizontal"  //添加分割线
              android:dividerPadding="5dp" //设置padding
              android:showDividers="middle">//居中显示
 
 
    <TextView android:layout_width="0dp"
              android:layout_weight="0.5"
              android:layout_height="wrap_content"
              android:gravity="center"
              style="@style/Text.Title"
              android:text="@string/batman_name"/>
 
    <TextView android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="0.5"
              android:gravity="center"
              style="@style/Text.Title"
              android:text="@string/superman_name"/>
 
</LinearLayout>

上面用到了三个xml属性:

divider -用来定义一个drawable或者color作为分割线

showDividers -指定分割线在哪里显示,它们可以显示在开始位置,中间,末尾或者选择不显示

dividerPadding -给divider添加padding

来源: https://www.jianshu.com/p/961442b8e5ef

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容