Android平台下实现渐变效果
来源:互联网 发布:pt域名注册 编辑:程序博客网 时间:2024/04/25 15:43
一、LinearGradient线性渐变
在android平台中提供了两种重载方式来实例化该类分别为,他们的不同之处为参数中第一种方法可以用颜色数组,和位置来实现更细腻的过渡效果,比如颜色采样int[] colors数组中存放20种颜色,则渐变将会逐一处理。而第二种方法参数仅为起初颜色color0和最终颜色color1。
LinearGradient(float x0, float y0, float x1, float y1, int[] colors, float[] positions, Shader.TileMode tile)
LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1, Shader.TileMode tile)
使用实例如下:
Paint p=new Paint();
LinearGradient lg=new LinearGradient(0,0,100,100,Color.RED,Color.BLUE,Shader.TileMode.MIRROR); //参数一为渐变起初点坐标x位置,参数二为y轴位置,参数三和四分辨对应渐变终点,最后参数为平铺方式,这里设置为镜像.
刚才Android开发网已经讲到Gradient是基于Shader类,所以我们通过Paint的setShader方法来设置这个渐变,代码如下:
p.setShader(lg);
canvas.drawCicle(0,0,200,p); //参数3为画圆的半径,类型为float型。
二、 RadialGradient镜像渐变
有了上面的基础,我们一起来了解下径向渐变。和上面参数唯一不同的是,径向渐变第三个参数是半径,其他的和线性渐变相同。
RadialGradient(float x, float y, float radius, int[] colors, float[] positions, Shader.TileMode tile)
RadialGradient(float x, float y, float radius, int color0, int color1, Shader.TileMode tile)
三、 SweepGradient角度渐变
对于一些3D立体效果的渐变可以尝试用角度渐变来完成一个圆锥形,相对来说比上面更简单,前两个参数为中心点,然后通过载入的颜色来平均的渐变渲染。
SweepGradient(float cx, float cy, int[] colors, float[] positions) //对于最后一个参数SDK上的描述为May be NULL. The relative position of each corresponding color in the colors array, beginning with 0 and ending with 1.0. If the values are not monotonic, the drawing may produce unexpected results. If positions is NULL, then the colors are automatically spaced evenly.,所以Android123建议使用下面的重载方法,本方法一般为NULL即可。
SweepGradient(float cx, float cy, int color0, int color1)
或者直接创建一个drawable:
GradientDrawable grad = new GradientDrawable(Orientation.TOP_BOTTOM,
new int[] { Color.BLACK, Color.WHITE });
this.getWindow().setBackgroundDrawable(grad);
本文转载自:http://xxw8393.blog.163.com/blog/static/37256834201072655832696/
- Android平台下实现渐变效果
- Android平台下实现渐变效果
- Android平台下实现渐变效果
- IE下线性渐变的效果实现
- android中使用shader实现渐变效果
- Android帧布局-实现渐变效果
- android实现alpha渐变动画效果
- Android的TitleBar实现透明度渐变效果
- Android Textview实现文字颜色渐变效果
- Android UI效果实现 滑动模糊渐变效果实现
- android实现文字渐变效果和歌词进度的效果
- android实现文字渐变效果和歌词进度的效果
- css实现渐变效果
- Android Shader渐变效果
- 关于Android平台下png图片渐变失真的解决办法
- Android设置Alpha值实现图片渐变效果
- android 自定义属性实现 ImageView 透明度渐变效果
- Android如何实现ListView的Item松开渐变效果?
- 在EVC下使用SQLite
- 路由器设置:没有交换机怎么实现上网?
- RejectedPolicy--DiscardPolicy
- 程序是设计出来的
- Perl数组的应用
- Android平台下实现渐变效果
- 如何写extjs 的多条件搜索框
- 嵌入式linuxTCP/IP路由器
- javascript验证邮箱格式代码
- Session原理
- undefined macro: AM_CONFIG_HEADER solution
- 为mysql的用户赋予权限
- android加载include
- 图像处理滤波器(三)——高斯平滑滤波器(Gaussian Smoothing Filter)