(转载)Android 开发shape的各种编写,边框,虚线,实线等

原文出处:
此博客
1、绘制边框:在res/drawable下建立XML文件,将其设置为背景即可:

代码:

<?xml version="1.0" encoding="utf-8"?>  
<shape xmlns:android="http://schemas.android.com/apk/res/android" >  
    <stroke  
            android:width="1dp"  
            android:color="#55666666"  
            />  
    <solid  
            android:color="#ffffff"  
            />  
    <padding  
            android:bottom="1dp"  
            android:left="1dp"  
            android:right="1dp"  
            android:top="1dp"  
            >  
    </padding>  
</shape> 

2、绘制椭圆:
代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- 圆角 -->
    <corners
        android:bottomLeftRadius="6dp"
        android:bottomRightRadius="6dp"
        android:radius="10dp"
        android:topLeftRadius="6dp"
        android:topRightRadius="6dp" />

    <!-- 描边 -->
    <solid
        android:width="1dp"
        android:color="@color/bg_Gray" />

</shape>

3、绘制实线:
代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >

    <stroke
        android:dashGap="0dp"
        android:dashWidth="2dp"
        android:width="1dp"
        android:color="#D5D5D5" />

    <size android:height="2dp" />

</shape>

4、绘制虚线:
代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >

    <stroke
        android:dashGap="2dp"
        android:dashWidth="3dp"
        android:width="1dp"
        android:color="#D5D5D5" />

    <size android:height="2dp" />

</shape>
发布了47 篇原创文章 · 获赞 51 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/qq_41976613/article/details/94730200
今日推荐