加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

安卓drawable基本属性corners、solid、gradient、stroke、size、padding详解

(2023-06-16 12:01:47)
分类: androidios
使用

 
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  >
   
 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_margin="50dip"
  android:text="@string/hello_world"  
  android:background="@drawable/shape_radius"/>
 

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13

基本属性(corners、solid、gradient、stroke、size、padding)

    corners:定义圆角

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

    1
    2
    3
    4
    5
    6

    solid:指定内部填充色
   

    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时才有渐变效果   

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

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

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

    1
    2
    3
    4
    5
    6

    size:定义图形的大小

 
 android:width="dimension"   
 android:height="dimension" />

    1
    2
    3

    padding:定义内部边距

 
 android:left="dimension"   
 android:top="dimension"   
 android:right="dimension"   
 android:bottom="dimension" />

    1
    2
    3
    4
    5

Shape的属性(rectangle、oval、line、ring)

    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
————————————————
版权声明:本文为CSDN博主「雨 渊」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_44352065/article/details/116654992

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有