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"/>

效果:







免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM