关于shape的应用很早以前就看到了,之所以现在才写这篇博客,因为博客园项目结束了,下一个2048小游戏还没有开始,趁着这个时间整理下自己的东西还是很有必要的。
玩手机的小伙伴们都知道,一个软件一眼能否吸引你,主要看他界面设计是否美观,这毕竟是个看脸的时代
先说下shape
资源文件里主要包括:边角(corners),渐变色(gradrent),大小(size),边距(padding) ,填充(solid),扫边(stoke)
先说下边角
<corners
android:radius=""
android:topLeftRadius=""
android:topRightRadius=""
android:bottomLeftRadius=""
android:bottomRightRadius="" />
每个值都是整数dp,设置的是边角半径
渐变色
<gradient
android:angle=""
android:centerColor=""
android:endColor=""
android:startColor=""
/>
第一个表示的是渐变渐变方向,必须是45的整数倍
大小
<size
android:width=""
android:height="" />
边距
<padding
android:left=""
android:top=""
android:right=""
android:bottom="" />
填充
<solid
android:color="color" />
扫边
<stroke
android:width=""
android:color="color"
android:dashWidth=""
android:dashGap="" />
上面两个表示实线,width
表示表示实线宽度,dashwidth表示虚线宽度,dashGap表示之间的间距
对了shape还有
android:shape=["rectangle" | "oval" | "line" | "ring"]
rectangle表示矩形
oval 椭圆
主要用这两个
上面六个主要说的是资源文件shape
前两天看书设置背景渐变色有一个类,GradientDrawable,也可以很灵活的设置渐变色
GradientDrawable g =new GradientDrawable(Orientation.TOP_BOTTOM,
new int[]{(int) (random.nextLong()%16777216),(int) (random.nextLong()%16777216),(int) (random.nextLong()%16777216),(int) (random.nextLong()%16777216)});
getWindow().setBackgroundDrawable(g);
我的颜色是随机的
,当然设置渐变背景色还可以用图像来渲染