android里的渐变色与shape

关于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);

我的颜色是随机的

,当然设置渐变背景色还可以用图像来渲染







  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值