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