温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android的shape属性和子属性如何使用

发布时间:2022-06-13 10:42:42 来源:亿速云 阅读:127 作者:iii 栏目:开发技术

这篇文章主要讲解了“Android的shape属性和子属性如何使用”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Android的shape属性和子属性如何使用”吧!

shape属性详解

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="30dp"
    android:innerRadiusRatio="2"
    android:shape="ring"
    android:thickness="2dp"
    android:thicknessRatio="3"
    android:useLevel="false">
</shape>
  • android:shape="line"  shape的形状,默认为矩形,可以设置为矩形(rectangle)、椭圆形(oval)、线性形状(line)、环形(ring) 

  • android:innerRadius  尺寸,内环的半径,仅是ring环形可用。 

  • android:innerRadiusRatio  浮点型,以环的宽度比率来表示内环的半径,比如环的宽度为50,比例为2.5,那么内环半径为20

  • android:thickness  尺寸,环的厚度 

  • android:thicknessRatio 浮点型,以环的宽度比率来表示环的厚度,和innerRadiusRatio相似

  • android:useLevel  boolean值,有时必须要加上她才有效果,写上就有效果了

子属性详解

<corners    //定义圆角   
    android:radius="10dp"      //全部的圆角半径,例:10dp  
    android:topLeftRadius="10dp"   //左上角的圆角半径,例:10dp  
    android:topRightRadius="10dp"  //右上角的圆角半径,例:10dp  
    android:bottomLeftRadius="10dp"    //左下角的圆角半径,例:10dp  
    android:bottomRightRadius="10dp" />    //右下角的圆角半径,例:10dp  
<solid android:color="#ffff00" /> //只有一个color,设置填充颜色即可。  
<gradient  
    android:type="linear"   //共有3中渐变类型,线性渐变(默认linear)/放射渐变(radial)/扫描式渐变(sweep)  
    android:angle="0"     //渐变角度,必须为45的倍数,0为从左到右,90为从上到下 ,仅在线性渐变生效  
    android:centerX="0.2"     //渐变中心X的相当位置,范围为0~1,多应用于放射渐变  
    android:centerY="0.1"     //渐变中心Y的相当位置,范围为0~1,多应用于放射渐变  
    android:startColor="#ff0000"   //渐变开始点的颜色  
    android:centerColor="#ffff00"  //渐变中间点的颜色,在开始与结束点之间   
    android:endColor="#00ff00"    //渐变结束点的颜色  
    android:gradientRadius="10"  //渐变的半径,只有当渐变类型为radial时才能使用   
    android:useLevel="false" />  //属性通常不使用。该属性用于指定是否将该shape当成一个LevelListDrawable来使用,默认值为false。
<stroke     
    android:width="dimension"    //表示描边的宽度 
    android:color="#00ff00"   //表示描边的颜色,例绿色 
    android:dashWidth="8dp"   //虚线的宽度,值为0时便是实线,例8dp宽
    android:dashGap="1dp" />   //虚线的间隔,例间隔1dp

感谢各位的阅读,以上就是“Android的shape属性和子属性如何使用”的内容了,经过本文的学习后,相信大家对Android的shape属性和子属性如何使用这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI