Android开发之渐变效果gradient属性

首先文档介绍:

 <gradientandroid: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"] />

<gradient>

shape的颜色渐变属性

attributes:

android:angle
Integer,代表渐变颜色的角度, 0 is left to right, 90 is bottom to top. 必须是45的整数倍. 
默认是 0.该属性只有在type=linear情况下起作用,默认的type为linear。

默认情况下,从左到右:

xml代码:<gradient 
        android:startColor="#000000"
        android:endColor="#ffffff"
        />

angle=270,从上到下 :

xml代码:<gradient 
        android:startColor="#000000"
        android:endColor="#ffffff"
        android:angle="270"
        />
android:startColor
Color. 颜色渐变的开始颜色,如angle=270中的 android:startColor="#000000"
android:endColor
Color. 颜色渐变的结束颜色,如angle=270中的  android:endColor="#ffffff"
android:centerColor
Color.  颜色渐变的中间颜色,主要用于多彩。
                               
<gradient 
        android:startColor="#000000"
        android:endColor="#ffffff"
        android:centerColor="#ff0000"
        />
android:centerX
Float.(0 - 1.0) 相对X的渐变位置。
android:centerY
Float.(0 - 1.0) 相对Y的渐变位置。  
这两个属性只有在type不为linear情况下起作用。
android:gradientRadius
Float. 渐变颜色的半径,单位应该是像素点. 需要 android:type="radial".
    如果android:type="radial",没有设置android:gradientRadius,将会报错,error inflating class.                                         
xml代码: <gradient 
        android:startColor="#ff0000"
        android:endColor="#ffffff"
        android:centerX="0.5"
        android:centerY="0.5"
        android:gradientRadius="30"
        android:type="radial"
        />

加入Android:centerColor属性

<gradient 
        android:startColor="#ff0000"
        android:endColor="#ffffff"
        android:centerColor="#000000"
        android:centerX="0.5"
        android:centerY="0.5"
        android:gradientRadius="30"
        android:type="radial"
        />
android:type

Value Description
"linear" 线性渐变.可以理解为 y=kx+b.
"radial" A radial gradient.圆形渐变,起始颜色从cenralX,centralY点开始。
"sweep" A sweeping line gradient.

centerX="0.2"   centerX="0.2"

xml代码:     <gradient 
        android:startColor="#ff0000"
        android:endColor="#ffffff"
        android:centerX="0.2"
        android:centerX="0.2"
        android:gradientRadius="30"
        android:type="radial"
        /> type="sweep":

xml代码:

<gradient 
        android:startColor="#ff0000"
        android:endColor="#ffffff"
        android:centerX="0.5"
        android:centerY="0.5"
        android:type="sweep"
        />

Android开发之渐变效果gradient属性相关推荐

  1. android开发笔记之系统属性(ro.com.google.clientidbase.ms)随卡适配

    客户要求 客户提了一个小需求,就是要将系统属性(ro.com.google.clientidbase.ms)随卡适配. 具体要求是: 如果插中国的卡,系统属性ro.com.google.clienti ...

  2. android android 修改 jpg exif 属性,Android开发之使用ExifInterface获取拍照后的图片属性...

    本文实例讲述了Android开发之使用ExifInterface获取拍照后的图片属性.分享给大家供大家参考,具体如下: ExifInterface exif = new ExifInterface(f ...

  3. Android开发笔记(九十六)集合动画与属性动画

    集合动画AnimationSet 补间动画有四大类:透明度动画AlphaAnimation.旋转动画RotateAnimation.缩放动画ScaleAnimation.平移动画TranslateAn ...

  4. Android开发笔记(八十四)使用Properties读写属性值

    Properties概述 Java中的配置文件常为.properties文件,而Properties类便是读写此类文件的工具.属性文件有两种格式,一种是文本格式,其内容是"键=值" ...

  5. 属性数量限制android,Android开发笔记 今天学到的一些属性

    Android开发笔记 今天学到的一些属性 更新时间:2012年11月07日 10:23:33   作者: 离开实验室之前再贴上今天下午自己学到的一些基础知识 上午干嘛了呢,忙着数据恢复呢 1.最后程 ...

  6. android开发笔记之属性动画

    属性动画简单介绍 作用对象:任意 Java 对象 不再局限于 视图View对象 实现的动画效果:可自定义各种动画效果 不再局限于4种基本变换:平移.旋转.缩放 & 透明度 特点 作用对象进行了 ...

  7. android textview点击部分,Android开发第二大控件,EditText的属性和使用方法

    EditText与TextView非常相似,它甚至与TextView 共用了绝大部分XML属性和方法.EditText与TextView的最大区别在于:EditText可以接受用户输入. 一.Edit ...

  8. android 渐变的背景色,Android开发——实现背景颜色渐变效果-Go语言中文社区

    前言 在Android开发当中,我们肯定会接到有业务需求是:让APP的某一些背景颜色产生渐变效果.那我们应该怎么去实现呢?接下就是我要为大家介绍的了. 效果图 这是需求要达到的效果.接下来说一下是怎么 ...

  9. Android开发中EditText:一、属性详解

    在android开发中,EditText组件是一个常用控件,也是一个比较重要的组件,它的基本属性需要熟练使用才行,接下来就来讲一下在Android开发中EditText组件的基本使用. 一.基本属性 ...

  10. android开发步步为营之90:android图片处理技术之三(Gradient渐变图片的绘制)

    我想大家在开发的时候,经常会看到UED会设计渐变颜色的产品需求,当然如果图片不需要动态更换,直接使用UED设计的渐变色的图片就可以了,但是很多时候,像我们最近项目里面,就有根据不同的皮肤,渐变色是不一 ...

最新文章

  1. SANS:2018年SOC调查报告
  2. js动态改变下拉菜单内容示例 .
  3. openjdk linux tomcat,linux下配置安装OpenJDK+Tomcat(示例代码)
  4. 虚拟实验工场大学计算机实验报告答案,虚拟实验实验报告 - 实验报告 - 书业网.doc...
  5. 演练-使用xapth与lxml库进行操作-0223
  6. jquery表格自动补全插件——datagrid
  7. 输入特定字符和只能输入数字。
  8. java encode乱码_java 中文乱码问题的解决
  9. 谷歌浏览器的一个新特点—关于获取iframe的parent对象
  10. Git:常用命令记录
  11. WPF: 自动设置Owner的ShowDialog
  12. 一键生成AppIcon 多种尺寸图标
  13. C++ opencv显示fps帧率
  14. 编程入门之C语言入门
  15. 设计一个程序,其中有三个类CBank,BBank,GBank,分别为中国银行类…………
  16. 如何在移动钱包中搭建一个小程序应用商店
  17. python算积分蒙特卡罗_蒙特卡罗计算积分
  18. 四/八电极测脂技术做蓝牙八电极脂肪秤方案
  19. 护照 MRZ码编码规则
  20. Python爬虫:BeautifulSoup的find()和findAll()

热门文章

  1. python英语单词 扇贝英语安卓下载_扇贝单词英语版app下载_靠谱的外语软件扇贝单词英语版下载安装 安卓版 V3.4.302 - 罐头安卓网...
  2. 打印html并去掉页眉页脚
  3. matlab text函数
  4. Arduino案例实操 -- OLED中文显示(IIC)
  5. python如何debug找到错误_调试python,我找不到哪里出错了?
  6. JavaCV本地视频流通过帧图片添加文本进行字幕合成
  7. Authorization Basic认证 笔记
  8. Windows中 配置DHCP服务器
  9. Python贪吃蛇双人大战-升级版
  10. STM32配合火焰传感器的火灾报警