android shape讲解小全及例子


原文:http://write.blog.csdn.net/postedit/50549154

例子:

<shapexmlns:android=http://schemas.android.com/apk/res/android

        android:shape=["rectangle" | "oval" |"line" |"ring"]> --- 默认为rectangle

    <corners--shape=“rectangle”时使用,

         android:radius="integer"-- 半径,会被下边的属性覆盖,默认为1dp

         android:topLeftRadius="integer"

         android:topRightRadius="integer"

         android:bottomLeftRadius="integer"

         android:bottomRightRadius="integer"/>

    <gradient-- 渐变

        android:angle="integer"

        android:centerX="integer"

        android:centerY="integer"

        android:centerColor="integer"

        android:endColor="color"

       android:gradientRadius="integer"

       android:startColor="color"

        android:type=["linear" | "radial" |"sweep"]

        android:useLevel=["true" | "false"]/>

<padding

       android:left="integer"

        android:top="integer"

        android:right="integer"

        android:bottom="integer"/>

    <size-- 指定大小,一般用在imageview配合scaleType属性使用。大小一般会适配滴

        android:width="integer"

        android:height="integer"/>

<solid-- 填充颜色,可是是十六进制颜色。(比如想设置半透明效果,直接使用十六就只就OK

        android:color="color"/>

    <stroke-- 指定边框,borderdashWidthdashGap有一个为0dp则为

        android:width="integer"

        android:color="color"

      android:dashWidth="integer"-- 虚线宽度

       android:dashGap="integer"/> -- 虚线间隔宽度

</shape>

元素:

   <shape>
android:shape中 rectangle 长方形, oval  椭圆形, line 线形, ring 环形
<corners> 圆角的弧度
android:radius 所有圆角的弧度
或设置
android:topLeftRadius
android:topRightRadius
android:bottomLeftRadius
android:bottomRightRadius
<gradient> 颜色渐变
android:angle 渐变的角度,它必须是45的倍数,默认值是0,  注意!!0度是在左边的中间,且逆时针 由小到大。
android:centerX android:centerY对渐变中心的相对位置
android:startColor起始颜色,一个十六进制的值或颜色资源。
android:endColor终止颜色
android:centerColor中间颜色

android:type 渐变的梯度模式

渐变默认的模式为android:type="linear",即线性渐变,

可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径android:gradientRadius="50"。sweep扫线梯度(不确定)

android:useLeveltrue是作为一个levellistdrawable

<padding>间隔,可以设置上下左右四个方向的间隔,这个就不用过多解释了,很常用。android:left android:top android:right  android:bottom

<size>  大小,  android:height  android:width

<solid>  填充颜色   android:color

<stroke> 描边

android:width线的厚度

android:color边线颜色

android:dashGap虚线的小线“-”之间的距离

android:dashWidth虚线的“-”,一个横线的宽度

原文:http://write.blog.csdn.net/postedit/50549154

例子:(圆角空心边框矩形背景,边框2dp)

 <?xml version="1.0" encoding="UTF-8"?>
 <shape xmlns:android=http://schemas.android.com/apk/res/android
     android:shape="rectangle" >
 
     <!-- 填充的颜色 -->
     <solid android:color="#FFFFFF" />
     <!-- 设置矩形的四个角为弧形 -->
     <!-- android:radius 弧形的半径 -->
     <corners android:radius="7dip" />
 <stroke     android:width="2dp"  /> -- 虚线间隔宽度

 </shape>











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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值