android布局中画线的方法

1.自定义View画线

下面介绍几种简单的方法
2.textView和View画直线

 
    
    1. <TextView
    2. android:layout_width="match_parent"
    3. android:layout_height="1dp"
    4. android:background="#bfbfbf" />

 
    
    1. <View
    2. android:layout_width="match_parent"
    3. android:layout_height="1dp"
    4. android:background="#FF909090"/>

background为设置直线的颜色
但是也只能画直线

3.自定义shape文件

dotted_line.xml文件
 
    
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:shape="line" >
    4. <stroke
    5. android:dashGap="3dp"
    6. android:dashWidth="6dp"
    7. android:width="1dp"
    8. android:color="#bfbfbf" />
    9. <!-- 虚线的高度 -->
    10. <size android:height="1dp" />
    11. </shape>
其中,破折线的宽度为dashWith,破折线之间的空隙的宽度为dashGap,当dashGap=0dp时,为实线

在你的xml布局中引用
 
    
    1. <LinearLayout
    2. android:layout_width="match_parent"
    3. android:layout_height="2dp"
    4. android:background="@drawable/dotted_line"
    5. android:layerType="software"/>

效果:






转载于:https://www.cnblogs.com/yjing/p/5313589.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值