Android Shape 属性详解

<?xml version="1.0" encoding="utf-8"?>  
<shape xmlns:android="http://schemas.android.com/apk/res/android" >  
 
</shape>  

基本属性

Corners

<corners    //定义圆角    
    android:radius="dimension"      //全部的圆角半径    
    android:topLeftRadius="dimension"   //左上角的圆角半径    
    android:topRightRadius="dimension"  //右上角的圆角半径    
    android:bottomLeftRadius="dimension"    //左下角的圆角半径    
    android:bottomRightRadius="dimension" />    //右下角的圆角半径    

solid

<solid  android:color="color" />    

gradient

gradient用以定义渐变色,可以定义两色渐变和三色渐变,及渐变样式,它的属性有下面几个:

<gradient   
    android:type=["linear" | "radial" | "sweep"]    //共有3中渐变类型,线性渐变(默认)/放射渐变/扫描式渐变    
    android:angle="integer"     //渐变角度,必须为45的倍数,0为从左到右,90为从上到下,仅对线性渐变有效
    android:centerX="float"     //渐变中心X的相当位置,范围为0~1    
    android:centerY="float"     //渐变中心Y的相当位置,范围为0~1    百分比
    android:startColor="color"   //渐变开始点的颜色    
    android:centerColor="color"  //渐变中间点的颜色,在开始与结束点之间    
    android:endColor="color"    //渐变结束点的颜色    
    android:gradientRadius="float"  //渐变的半径,只有当渐变类型为radial时才能使用    
    android:useLevel=["true" | "false"] />  //使用LevelListDrawable时就要设置为true。设为false时才有渐变效果    

示例:

在这里插入图片描述

在构造放射性渐变时,要加上android:gradientRadius属性(渐变半径),即必须指定渐变半径的大小才会起作用。

  • 线性渐变:
<gradient   
        android:type="linear"  
        android:startColor="#ff0000"  
        android:centerColor="#00ff00"  
        android:endColor="#0000ff"/>  
  • 放射性渐变:
<gradient   
        android:type="radial"  
        android:startColor="#ff0000"  
        android:centerColor="#00ff00"  
        android:endColor="#0000ff"  
        android:gradientRadius="100"/>  
  • 扫描式渐变:
<gradient   
        android:type="sweep"  
        android:startColor="#ff0000"  
        android:centerColor="#00ff00"  
        android:endColor="#0000ff"/>  

stroke

描边属性,可以定义描边的宽度,颜色,虚实线等

<stroke         
    android:width="dimension"   //描边的宽度    
    android:color="color"   //描边的颜色    
    // 以下两个属性设置虚线   
    android:dashWidth="dimension"   //虚线的宽度,值为0时是实线    
    android:dashGap="dimension" />      //虚线的间隔   

属性意义:
在这里插入图片描述
示例:

<stroke   
        android:width="20dp"   
        android:color="#00ff00"  
        android:dashWidth="10dp"  
        android:dashGap="1dp" />  

在这里插入图片描述

Shape属性

android:shape=["rectangle" | "oval" | "line" | "ring"]    
shape的形状,默认为矩形,可以设置为矩形(rectangle)、椭圆形(oval)、线性形状(line)、环形(ring)   
下面的属性只有在android:shape="ring时可用:    
android:innerRadius         尺寸,内环的半径。   
android:innerRadiusRatio    浮点型,以环的宽度比率来表示内环的半径,   
android:thickness           尺寸,环的厚度   
android:thicknessRatio      浮点型,以环的宽度比率来表示环的厚度,例如,如果android:thicknessRatio="2",    
android:useLevel            boolean值,如果当做是LevelListDrawable使用时值为true,否则为false.  
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值