shape用法知多少

首先看下效果图:

152741_iw8G_109481.jpg

shape中有以下几个重要属性:

corners —圆角 、gradient —渐变、padding —内容离边界距离、size—大小、solid —填充颜色、

stroke —描边


<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns: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”  --渐变角度,必须为45的整数倍
        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    -- 指定边框,border,dashWidth和dashGap有一个为0dp则为
        android:width=“integer”  --描边的宽度
        android:color=“color”   --描述的颜色
        android:dashWidth="integer"    -- 虚线宽度
        android:dashGap="integer" />    -- 虚线间隔宽度
</shape>







参考:疯狂android讲义   android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)

Android设置虚线、圆角、渐变   Android:res之shape制作圆角、虚线、渐变  Android中的Shape使用总结



转载于:https://my.oschina.net/cuitongliang/blog/486156

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值