安卓交互之shape的学习

为了实现透明边框的圆角矩形的按钮背景,所以了解了一下shape的各项属性

1.shape中常用的属性如下:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape=["rectangle" | "oval" | "line" | "ring"] > //有四种属性值,矩形,椭圆,线,圆环
    <corners //用于控制圆角的弧度
        android:radius="integer"
        android:topLeftRadius="integer"
        android:topRightRadius="integer"
        android:bottomLeftRadius="integer"
        android:bottomRightRadius="integer" />
    <gradient //渐变
        android:angle="integer"//渐变角度,0是从左倒右,90是下到上,180是右到左,270是上到下

android:centerX="integer" //0-1,渐变的X轴起始位置

        android:centerY="integer"//0-1,渐变的Y轴起始位置
        android:centerColor="integer" //中间的颜色
        android:endColor="color" //渐变结束颜色
        android:gradientRadius="integer"//渐变颜色的半径,需要设置android:type="radial"
        android:startColor="color" //渐变起始颜色
        android:type=["linear" | "radial" | "sweep"] //分为三种,linear是线性渐变,radial放射渐变,sweep扫描渐变
        android:useLevel=["true" | "false"] />
    <padding //内边距
        android:left="integer"
        android:top="integer"
        android:right="integer"
        android:bottom="integer" />
    <size //控制绘制的图形的长宽
        android:width="integer"
        android:height="integer" />
    <solid //填充的颜色值,全部区域
        android:color="color" />
    <stroke //描边
        android:width="integer" //边框大小
        android:color="color" //边框颜色
        android:dashWidth="integer" //虚线间距宽度
        android:dashGap="integer" /> //虚线宽度
</shape>

2.实现例子


3.demo源代码地址:http://download.csdn.net/detail/ling1008123/9889181

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值