shape使用总结

来源:互联网 发布:黑客入侵网站盗取数据 编辑:程序博客网 时间:2024/06/07 00:59

圆角矩形

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >    <corners android:radius="5.0dp" />    <solid android:color="#f09738" /></shape>

这里写图片描述


圆柱

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android">    <solid android:color="@color/colorAccent" />    <size        android:width="15dp"        android:height="15dp" />    <corners android:radius="40dp" /></shape>

这里写图片描述


<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="oval">    <size        android:width="15dp"        android:height="15dp" />    <solid android:color="#f09738" /></shape>

这里写图片描述


带边框的圆角矩形(圆柱带边框,圆形带边框同理)

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >    <corners android:radius="5.0dp" />    <solid android:color="#f09738" />    <stroke android:width="3dp"        android:color="#ffffff"/></shape>

这里写图片描述


渐变

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >    <gradient        android:startColor="#ff0000"        android:centerColor="#00ff00"        android:endColor="#ff0000"        android:angle="45" /></shape>

这里写图片描述


环形渐变(起始,终点颜色相同)

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="oval">    <gradient        android:endColor="#0000ff"        android:centerColor="#00ff00"        android:startColor="#0000ff"        android:type="sweep" /></shape>

这里写图片描述


发光圆圈

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">    <item>        <shape android:shape="oval">            <stroke                android:width="4dp"                android:color="#0C00F9" />            <corners android:radius="25dp" />        </shape>    </item>    <item        android:bottom="4dp"        android:left="4dp"        android:right="4dp"        android:top="4dp">        <shape android:shape="oval">            <stroke                android:width="4dp"                android:color="#FFF" />            <corners android:radius="25dp" />        </shape>    </item>    <item        android:bottom="6dp"        android:left="6dp"        android:right="6dp"        android:top="6dp">        <shape android:shape="oval">            <stroke                android:width="3dp"                android:color="#0C00F9" />            <corners android:radius="25dp" />        </shape>    </item></layer-list>

这里写图片描述


发光矩形

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">    <item>        <shape>            <stroke                android:width="4dp"                android:color="#0C00F9" />            <corners android:radius="2dp" />        </shape>    </item>    <item        android:bottom="4dp"        android:left="4dp"        android:right="4dp"        android:top="4dp">        <shape>            <stroke                android:width="4dp"                android:color="#FFF" />            <corners android:radius="2dp" />        </shape>    </item>    <item        android:bottom="6dp"        android:left="6dp"        android:right="6dp"        android:top="6dp">        <shape>            <stroke                android:width="3dp"                android:color="#0C00F9" />            <corners android:radius="2dp" />        </shape>    </item></layer-list>

这里写图片描述


渐变圆环

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">    <item>        <shape android:shape="oval">            <!--android:centerColor="#00ff00"-->            <gradient                android:startColor="#00ff00"                android:endColor="#ff0000"                android:angle="45" />        </shape>    </item>    <item        android:bottom="6dp"        android:left="6dp"        android:right="6dp"        android:top="6dp">        <shape android:shape="oval">            <corners android:radius="25dp" />            <solid android:color="#ffffff"/>        </shape>    </item></layer-list>

这里写图片描述


虚线边框

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >    <stroke        android:dashGap="2dp"        android:dashWidth="2dp"        android:width="1px"        android:color="#ffffff" />    <size android:height="1.0dp"/>    <corners android:radius="5.0dp" />    <solid android:color="#cc000000" /></shape>

这里写图片描述


带阴影的渐变圆环

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">    <item>        <shape android:shape="oval">            <!--android:centerColor="#00ff00"-->            <gradient                android:startColor="#00ff00"                android:endColor="#ff0000"                android:angle="45" />        </shape>    </item>    <item        android:bottom="6dp"        android:left="6dp"        android:right="6dp"        android:top="6dp">        <shape android:shape="oval">            <corners android:radius="25dp" />            <solid android:color="#ffffff"/>        </shape>    </item>    <item        android:bottom="9dp"        android:left="9dp"        android:right="9dp"        android:top="12dp">        <shape android:shape="oval">            <corners android:radius="25dp" />            <solid android:color="#cccccccc"/>        </shape>    </item>    <item        android:bottom="12dp"        android:left="12dp"        android:right="12dp"        android:top="12dp">        <shape android:shape="oval">            <corners android:radius="25dp" />            <solid android:color="#ffffff"/>        </shape>    </item></layer-list>

这里写图片描述


虚线

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="line" >    <!--线宽为dashWith,线之间空隙dashGap,dashGap=0dp时,是实线 -->    <stroke        android:dashGap="2dip"        android:dashWidth="4dip"        android:width="1px"        android:color="@color/white" />    <size android:height="1px" /></shape>

使用虚线的时候,要在代码中加上:
dottedLine.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
这句是去掉虚线的硬件加速,否则在某些手机上,显示的是一条实线


目前只研究了这些,欢迎大家补充