android shape使用总结

来源:互联网 发布:淘宝怎么截图发给别人 编辑:程序博客网 时间:2024/06/09 21:59

使用shape可以创建出好看的view,下面是自己总结的shap相关的属性介:

使用步骤:

1.在res下面新建文件夹drawable,在drawable文件夾新建xxx.xml,你可以点击drawable,右键-new-android xml file ,在彈出菜單,填入xml的名称,下面选择,shap,如图:


xml建立好后,我们就可以在里面根据自己需求,去设置相应的属性了。


属性介绍:

corners设定控件的圆角,例如: <corners android:radius="5dp" ></corners>,设置控件的4个脚为5dp的圆角。如果不想全部设置为圆角,或者圆弧大小不一,还可以这样设置:

 <corners android:topLeftRadius="" android:topRightRadius=" "  android:bottomLeftRadius=""  android:bottomRightRadius=""/>

分别设置,左上,右上,左下,右下的圆角,等号里面填相应的dp,4个属性,可以是1个或者多个,看自己需求

solid设定控件的填充颜色,和背景差不多

<solid android:color="#000000" ></solid>,设定控件背景为黑色

padding:设置控件中文字和边框的间距。例

 <padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" ></padding>

stroke:设定控件边框样式

 <stroke android:width="1dp" android:color="#FF0000"    />,width,边框的宽度,color边框颜色

  <stroke android:dashWidth="6dp" android:dashGap="2dp" android:width="1dp" android:color="#FF0000" ></stroke>

dashWidthdashGap设置控件边框为虚线样式,dashWidth,每个小虚线的长度,虚线中间的间距


gradient设置渐变

<gradient android:startColor="#FF0000" android:centerColor="#FF00FF" android:endColor="#EEB422" ></gradient>

startColor,开始颜色,centerColor:中间颜色,endColor,结束颜色,渐变默认为线性渐变,从做到右,我们可以设置其渐变方式和方向

<gradient android:startColor="#FF0000" android:centerColor="#FF00FF" android:endColor="#EEB422"android:angle="90" ></gradient>

angle属性可以设置其渐变方向,值为45的整数倍

渐变方式: android:type="" ,3中可选:radial,linear,sweep 默认为线性,其中android:type="radial"需要和android:gradientRadius=""(值为整数)一起使用才有效





原创粉丝点击