Resounces之ShapeDrawable

一 前言
        shapeDrawable用来定义基本的几何图形,例如 oval(椭圆) line(直线) ring(环形) rectangle(矩形),在xml自定义时使用标签<shape.../>,放置到res/drawable目录下。
二 shape子元素
1 corners
corners用来绘制几何图形的四个角的弧度,其属性有:

android:Radius                     设置四个角的半径

android:topLeftRadius           设置左上角的半径 

android:topRightRadius         设置右上角的半径 

android:bottomLeftRadius     设置右下角的半径 

android:bottomRightRadius   设置左下角的半径


stroke
stroke用来绘制几何图形的边框,属性:
width 边框的宽度
dashWidth dashGap 同时使用设置边框为虚线
dashWidth 为 每一截虚线的实的部分的宽度
dashGap 为 每一截虚线的虚的部分的宽度
padding
     设置几何图形的内边距,属性有left、bottom、top、right。

4 solid
   填充几何图形,只能一种颜色,其属性也只有一个color 即填充所使用的颜色。
5 size 
   设置几何图形的大小,其属性:
width:几何图像的宽度
height :几何图像的高度
6 gradient
    填充几何图形,作用和solid一样,但它最多可以设置三种颜色,即启始颜色、中间颜色、结束颜色,从开始到结束形成颜色的渐变填充,
属性有:
type 填充类型 linear线性  radial(放射形)  sweep(扫形)
startColor 启示的颜色
centerColor 中间的颜色
endColor 结束的颜色
centerX centerY 设置中心的位置
angle  角度值  值必须是45的倍数
gradientRadius 填充半径
三 示例
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<!--shape 属性值有:oval(椭圆) line(直线) ring(环形) rectangle(矩形)-->

<!--渐变色填充
type 填充类型 linear线性 radial(放射形) sweep(扫形)
startColor 启示的颜色
centerColor 中间的颜色
endColor 结束的颜色
centerX centerY 设置中心的位置
angle 角度值 值必须是45的倍数
gradientRadius 填充半径
-->
<gradient
android:angle="90"
android:centerX="50"
android:centerY="100"
android:startColor="@android:color/holo_red_light"
android:centerColor="@android:color/holo_green_light"
android:endColor="@android:color/holo_blue_dark"
android:type="linear"
android:gradientRadius="100dp"/>
<!--设置几何形状的大小-->
<size
android:height="100dp"
android:width="200dp"/>

<!--绘制四角的弧度-->
<corners
android:radius="10dp"
android:bottomLeftRadius="1dp"
android:bottomRightRadius="2dp"
android:topLeftRadius="5dp"
android:topRightRadius="10dp"
/>

<!--单色填充-->
<!--<solid-->
<!--android:color="@android:color/holo_orange_light"/>-->

<!--设置边框
属性:
width 边框的宽度
dashWidth dashGap 同时使用设置边框为虚线
dashWidth 为 每一截虚线的实的部分的宽度
dashGap 为 每一截虚线的虚的部分的宽度
-->

<stroke
android:color="@android:color/holo_orange_light"
android:dashWidth="20dp"
android:dashGap="10dp"
android:width="5dp"/>

<!--设置内边距-->
<padding
android:bottom="5dp"
android:top="5dp"
android:left="5dp"
android:right="5dp"/>

</shape>
效果图:


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值