安卓交互之shape的学习

来源:互联网 发布:手机淘宝我的课程在哪 编辑:程序博客网 时间:2024/06/05 14:58

为了实现透明边框的圆角矩形的按钮背景,所以了解了一下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

原创粉丝点击