最近项目风格走的卡片风,运用了许多渐变背景,虽然可以利用点9图可以进行拉伸,但是跟设计师调图也是蛮费劲,所以利用drawable中的gradient 画一个背景,记录一下.

首先放一张效果图:


Android 利用drawable中的gradient属性实现背景颜色渐变_第1张图片 线性渐变


Android 利用drawable中的gradient属性实现背景颜色渐变_第2张图片 梯度渐变

代码:

        android:angle="integer"

        android:centerX="integer"

        android:centerY="integer"

        android:centerColor="integer"

        android:endColor="color"

        android:gradientRadius="integer"

        android:startColor="color"

        android:type=["linear" | "radial" | "sweep"]

        android:useLevel=["true" | "false"] />


android:angle="integer"

Integer,代表渐变颜色的角度, 0 is left to right, 90 is bottom to top. 必须是45的整数倍. 

默认值0, 在type = "linear"下起作用. 默认情况是从左到右渐变 

android:startColor="# f8c62f"

 android:endColor="# 119dff"

 android:centerColor=" #FF4081t"

分别是 渐变色中的开始颜色  结束颜色  中间的渐变颜色

android:centerX

Float.(0-1.0) 相对X的渐变位置

android:centerY

Float.(0-1.0) 相对Y的渐变位置

这两个属性只有在不是 type = "linear" 的情况下才起作用 

android:gradientRadius

Float. 渐变色的半径,单位应该是像素点. 需要 android:type="radial":

android: type

"linear"  : 线性渐变. 大概为 y= ax+b;

"radial" : 圆形渐变,起始颜色从cenralX,centralY 点开始

"sweep" : 梯度渐变

更多相关文章

  1. 【转】Android背景选择器Selector详解
  2. android设置背景色为透明
  3. android 各种控件颜色值
  4. 浅谈android的selector背景选择器
  5. Android开发,使用xml drawable制作带边框的背景图

随机推荐

  1. android value 42 报错
  2. Android沉浸式通知栏的一个开源库SystemB
  3. 【android】recycleview小整理
  4. Android中网络判断
  5. Android(安卓)P2P语音通话实现
  6. android 颜色16进制对应的xml配置值(工具
  7. android: content URI的真实路径获取
  8. android 我的功能模块模板布局之一
  9. Android(安卓)禁止下拉通知栏
  10. android截图代码