Android中xml中shape的属性助记

    xiaoxiao2021-12-14  21

    Android中xml中shape的属性助记 2015-07-30 21:37:03 标签: Android  xml  shape 原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://ziruo.blog.51cto.com/10107518/1680349

    对于shape的一些属性老是忘记,每次都要去查找,为了方便我就自己记录下来,方便以后忘记了再查看这些属性。

    在shape中有几个属性rectangle、oval、line、ring 1.环形ring     在shape标签中把shape属性设置为ring类型     然后在shape标签中设置以下属性(这些属性只能在shape值为ring是使用)     android:innerRadius       内环的半径,尺寸单位是dp(不设置这个参数,会有个默认值)     android:thickness           环的宽度,尺寸单位是dp(一定要设置的参数)     android:useLevel            boolean值,如果当做是LevelListDrawable使用时值为true,否则为false. (这条属性一定要设置,不然看不见效果,暂时先设置为false)          android:innerRadiusRatio    浮点型,以环的宽度比率来表示内环的半径。默认是9,就是环的宽度乘以9再除以2就是内环半径的长度     android:thicknessRatio      浮点型,以环的宽度比率来表示环的厚度。      2.椭圆oval     可以通过子标签size设置椭圆大小,当宽和高相等时就是圆。一般也不再子标签size中设置宽高,而是设置控件的宽高。      3.矩形rectangle     可以通过子标签size标签设置矩形大小,当宽和高相等时就是正方形。一般也不再子标签size中设置宽高,而是设置控件的宽高。     在shape没有指定时,默认就是矩形      4.直线line     可以画一条直线,也可以画一条虚线     在shape的子标签中有gradient、corners、padding、size、solid、stroke 1.描形状的线stroke     android:width="dimension"   线的粗细     android:color="color"            线的颜色     // 以下两个属性是设置虚线时使用,实线不设置这两个属性     android:dashWidth="dimension"       每节虚线的长度     android:dashGap="dimension"          每节虚线直接的间隙宽度      注:在画ring,line时这个属性必须设置,在画oval,rectangle时需要描边就设置,不需要就不设置 2.填充颜色solid     android:color="color"   需要填充形状内部颜色时使用这个属性          注:在画line时不要设置这个属性,在画ring,oval,rectangle是需要实心就设置,需要空心就不设置      3.设置图片大小size     android:width="dimension"          设置宽度     android:height="dimension"         设置高度          注:在画oval时宽高相等就是圆形,在画rectangle是宽高相等就是正方形,不过一般不在这里设置,基本在控件设置宽高 4.内边距padding     android:left="dimension"      设置左内边距     android:top="dimension"            设置上内边距     android:right="dimension"        设置右内边距     android:bottom="dimension"        设置下内边距     注:一般不用设置这个属性 5.圆角corners     android:radius="dimension"            全部的圆角半径     //上面全部都圆角,和下面四个属性不共存,要么全部都圆角,要么根据下面属性给每个角设置     android:topLeftRadius="dimension"     左上角的圆角半径         android:topRightRadius="dimension"    右上角的圆角半径         android:bottomLeftRadius="dimension"  左下角的圆角半径         android:bottomRightRadius="dimension" 右下角的圆角半径      注:圆角一般是在rectangle情况下使用 6.渐变色gradient    android:type=["linear" | "radial" | "sweep"]    共有3中渐变类型,线性渐变(默认)/放射渐变/扫描式渐变   android:startColor="color"       渐变开始点的颜色       android:centerColor="color"      渐变中间点的颜色,在开始与结束点之间       android:endColor="color"         渐变结束点的颜色    android:angle="integer"              渐变角度,必须为45的倍数,0为从左到右,90为从上到下    android:gradientRadius="float"   渐变的半径,只有当渐变类型为radial时才能使用   android:centerX="float"          渐变中心X的相当位置,范围为0~1,从左到右,默认0.5   android:centerY="float"          渐变中心Y的相当位置,范围为0~1,从上到下,默认0.5   android:useLevel="boolean"       使用LevelListDrawable时就要设置为true。设为false时才有渐变效果     注:当类型type为linear时,angle属性才有效;当类型type为radial时,gradientRadius属性必须设置;当类型type为sweep时,centerX和centerY属性才有效。

    转载请注明原文地址: https://ju.6miu.com/read-964066.html

    最新回复(0)