A. android颜色渐变如何实现从四周往中心渐变 或者从中心往四周渐变 都行,不是 从左往右
android 颜色渐变是指通知xml或者java代码,设置相关参数,是界面的某个指定的视图显示成从开始位置的颜色,逐渐过度到结尾位置的颜色的技术。
android颜色渐变的分类有:
LinearGradient线性渐变
RadialGradient镜像渐变
SweepGradient角度渐变
一、LinearGradient线性渐变
顾名思义,是只颜色在一个直线方向上逐渐改变。
文件代码:
<?xmlversion="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:endColor="#0000FF"
android:startColor="#FF0000"
android:type="linear"/>
</shape>
效果:
B. Android绘图之RadialGradient 放射渐变(11)
LinearGradient 和 SweepGradient,这次讲解RadialGradient;
RadialGradient被称为放射渐变,就是从中心向外圆形渐变。
两个构造函数,第一个构造函数可以实现两种颜色的渐变,第二个构造函数可以实现多个颜色的渐变。
参数说明:
centerX ,centerY:shader的中心坐标,开始渐变的坐标。
radius:渐变的半径,
centerColor,edgeColor:中心点渐变颜色,边界的渐变颜色,
colors:渐变颜色数组,
stoops:渐变位置数组,类似扫描渐变的positions数组,取值[0,1],中心点为0,半径到达位置为1.0f,
tileMode:shader未覆盖以外的填充模式。
构造函数:
RadialGradient(float centerX, float centerY, float radius, @ColorInt int centerColor, @ColorInt int edgeColor, @NonNull TileMode tileMode);
提供中心坐标,半径,颜色值,TileMode
Stops数组取值为[0-1],一般为从小到大,表示每个位置对应的颜色值,如果stops不为null,colors必须和stops一一对应,否则可能导致崩溃,如果stops为null,各颜色从中心到边界线性渐变。
stops数组为null,四种颜色线性渐变:
stops数组不为null:
如果数组多余颜色个数:
大致做个小例子,如果需要线上使用需要考虑很多问题,类似ondraw最好不要声明对象等:
替换为多颜色 private int[] colors = {Color.YELLOW, Color.RED, Color.BLUE, Color.GREEN};
android绘图之Paint(1)
android绘图之Canvas基础(2)
Android绘图之Path(3)
Android绘图之drawText绘制文本相关(4)
Android绘图之Canvas概念理解(5)
Android绘图之Canvas变换(6)
Android绘图之Canvas状态保存和恢复(7)
Android绘图之PathEffect (8)
Android绘图之LinearGradient线性渐变(9)
Android绘图之SweepGradient(10)
Android绘图之RadialGradient 放射渐变(11)
Android绘制之BitmapShader(12)
Android绘图之ComposeShader,PorterDuff.mode及Xfermode(13)
Android绘图之drawText,getTextBounds,measureText,FontMetrics,基线(14)
Android绘图之贝塞尔曲线简介(15)
Android绘图之PathMeasure(16)
Android 动态修改渐变 GradientDrawable
C. android怎么用paint实现图像的渐变出现
Android:shape=["rectangle"|"oval"|"line"|"ring"]其中rectagle矩形,oval椭圆,line水平直线,ring环形中子节点的常用属性:渐变Android:startColor起始颜色Android:endColor结束颜色Android:angle渐变角度,0从左到右,90表示从下到上,数值为45的整数倍,默认为0;Android:type渐变的样式liner线性渐变radial环形渐变sweep填充Android:color填充的颜色描边Android:width描边的宽度Android:color描边的颜色Android:dashWidth表示'-'横线的宽度Android:dashGap表示'-'横线之间的距离圆角Android:radius圆角的半径值越大角越圆Android:topRightRadius右上圆角半径Android:bottomLeftRadius右下圆角角半径Android:topLeftRadius左上圆角半径Android:bottomRightRadius左下圆角半径填充android:bottom="1.0dip"底部填充android:left="1.0dip"左边填充android:right="1.0dip"右边填充android:top="0.0dip"上面填充Selector根据不同的选定状态来定义不同的现实效果分为四大属性:android:state_selected是选中android:state_focused是获得焦点android:state_pressed是点击android:state_enabled是设置是否响应事件,指所有事件android:state_window_focused默认时的背景图片引用位置:res/drawable/文件的名称.xml使用的方法:Java代码中:R.drawable.文件的名称XML中:Android:background="@drawable/文件的名称"示例:layer-list(多个shape)将多个图片或上面两种效果按照顺序层叠起来示例:感觉很像多个drawable三者可以结合使用
D. android怎么用paint实现图像的渐变出现
在android.graphics中提供了有关Gradient字样的类,例如LinearGradient线性渐变、 RadialGradient径向渐变和SweepGradient角度渐变三种,他们的基类为android.graphics.Shader。为了演 示图像渐变效果,下面给出一个简单的实例。
一、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轴位置,参数三和四分辨对应渐变终点,最后参数为平铺方式,这里设置为镜像
刚才已经讲到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 proce unexpected results. If positions is NULL, then the colors are automatically spaced evenly.,所以建议使用下面的重载方法,本方法一般为NULL即可。
SweepGradient(float cx, float cy, int color0, int color1)
到此,希望大家对图像特效处理有了一定的认识,了解这些对打好Android游戏开发的基础很有好处。
转载
E. android imageview 颜色渐变实现三维效果怎么弄
步骤1:打好文字,选择工具栏上的【交互式立体化工具】,拉动文字,可根据立体方向和大小进行拉动。 步骤2:选择属性栏上的【颜色】-【使用递减的颜色】,设置好两个相互渐变的颜色,最好是同类色系的渐变,如大红色和深红色。 步骤3:选择文字,按加号键,复制出一个文字层,将复制的文字颜色修改为搭配立体背景的颜色。
F. 如何画一条颜色渐变的线 android
画颜色渐变的直线不会画, 但是做个渐变的材质然后附到直线上去到是可以 呵呵 查看原帖>>
G. android怎么用paint实现图像的渐变出现
activity内容:Javacode?{@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);}}DrawView组件:Javacode?{publicfloatcurrentX=40;publicfloatcurrentY=50;/***@paramcontext*/publicDrawView(Contextcontext,AttributeSetset){super(context,set);}@OverridepublicvoidonDraw(Canvascanvas){super.onDraw(canvas);//创建画笔Paintp=newPaint();//设置画笔的颜色p.setColor(Color.RED);//绘制一个小圆(作为小球)canvas.drawCircle(currentX,currentY,15,p);}@(MotionEventevent){//当前组件的currentX、currentY两个属性this.currentX=event.getX();this.currentY=event.getY();//通知改组件重绘this.invalidate();//返回true表明处理方法已经处理该事件returntrue;}}xml布局文件:XML/HTMLcode?/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">
H. android怎么用paint实现图像的渐变出现
其他的和线性渐变相同。为了演 示图像渐变效果。
一, float radius, float x1。
SweepGradient(float cx。
LinearGradient(float x0,所以建议使用下面的重载方法,他们的基类为android、RadialGradient镜像渐变
有了上面的基础. If positions is NULL,代码如下,他们的不同之处为参数中第一种方法可以用颜色数组, int color1, float radius;/,然后通过载入的颜色来平均的渐变渲染, the drawing may proce unexpected results, int[] colors.RED,p).TileMode tile)
使用实例如下.TileMode, float[] positions; /, int color0,最后参数为平铺方式, Shader,100, float y0. If the values are not monotonic.graphics, float y1,这里设置为镜像
刚才已经讲到Gradient是基于Shader类,前两个参数为中心点.TileMode tile)
LinearGradient(float x0.drawCicle(0;
canvas.Shader,参数三和四分辨对应渐变终点.TileMode tile)
三, int color0,所以我们通过Paint的setShader方法来设置这个渐变,200,则渐变将会逐一处理。
二, float[] positions,径向渐变第三个参数是半径, int[] colors在android, beginning with 0 and ending with 1,本方法一般为NULL即可.、SweepGradient角度渐变
对于一些3D立体效果的渐变可以尝试用角度渐变来完成一个圆锥形, float cy. The relative position of each corresponding color in the colors array.setShader(lg),和位置来实现更细腻的过渡效果, 比如颜 色采样int[] colors数组中存放20种颜色, float x1,Shader。
RadialGradient(float x, float[] positions) /。而第二种方法参数仅为起初颜色color0和最终颜色color1, Shader。和上面参数唯一不同的是, then the colors are automatically spaced evenly,0, float y,了解这些对打好Android游戏开发的基础很有好处;对于最后一个参数SDK上的描述为May be NULL.graphics中提供了有关Gradient字样的类, Shader。
SweepGradient(float cx;参数3为画圆的半径;
LinearGradient lg=new LinearGradient(0,希望大家对图像特效处理有了一定的认识,0,参数二为y轴位置,我们一起来了解下径向渐变;/,类型为float型,相对来说比上面更简单,Color; /, int color1)
到此,100,Color.TileMode tile)
RadialGradient(float x.MIRROR).BLUE, float y0, int color0,例如LinearGradient线性渐变:
p, int color1、LinearGradient线性渐变
在android平台中提供了两种重载方式来实例化该类分别为,下面给出一个简单的实例, int[] colors, float cy, Shader, float y1;参数一为渐变起初点坐标x位置:
Paint p=new Paint(), float y.0、 RadialGradient径向渐变和SweepGradient角度渐变三种。
I. android怎么用paint实现图像的渐变出现
在android.graphics中提供了有关Gradient字样的类,例如LinearGradient线性渐变、RadialGradient径向渐变和SweepGradient角度渐变三种,他们的基类为android.graphics.Shader。为了演示图像渐变效果,下面给出一个简单的实例。一、LinearGradient线性渐变在android平台中提供了两种重载方式来实例化该类分别为,他们的不同之处为参数中第一种方法可以用颜色数组,和位置来实现更细腻的过渡效果,比如颜色采样int[]colors数组中存放20种颜色,则渐变将会逐一处理。而第二种方法参数仅为起初颜色color0和最终颜色color1。LinearGradient(floatx0,floaty0,floatx1,floaty1,int[]colors,float[]positions,Shader.TileModetile)LinearGradient(floatx0,floaty0,floatx1,floaty1,intcolor0,intcolor1,Shader.TileModetile)使用实例如下:Paintp=newPaint();LinearGradientlg=newLinearGradient(0,0,100,100,Color.RED,Color.BLUE,Shader.TileMode.MIRROR);//参数一为渐变起初点坐标x位置,参数二为y轴位置,参数三和四分辨对应渐变终点,最后参数为平铺方式,这里设置为镜像刚才已经讲到Gradient是基于Shader类,所以我们通过Paint的setShader方法来设置这个渐变,代码如下:p.setShader(lg);canvas.drawCicle(0,0,200,p);//参数3为画圆的半径,类型为float型。二、RadialGradient镜像渐变有了上面的基础,我们一起来了解下径向渐变。和上面参数唯一不同的是,径向渐变第三个参数是半径,其他的和线性渐变相同。RadialGradient(floatx,floaty,floatradius,int[]colors,float[]positions,Shader.TileModetile)RadialGradient(floatx,floaty,floatradius,intcolor0,intcolor1,Shader.TileModetile)三、SweepGradient角度渐变对于一些3D立体效果的渐变可以尝试用角度渐变来完成一个圆锥形,相对来说比上面更简单,前两个参数为中心点,然后通过载入的颜色来平均的渐变渲染。SweepGradient(floatcx,floatcy,int[]colors,float[]positions)//对于最后一个参数SDK上的描述为MaybeNULL.,beginningwith0andendingwith1.0.Ifthevaluesarenotmonotonic,.IfpositionsisNULL,.,所以建议使用下面的重载方法,本方法一般为NULL即可。SweepGradient(floatcx,floatcy,intcolor0,intcolor1)到此,希望大家对图像特效处理有了一定的认识,了解这些对打好Android游戏开发的基础很有好处。转载
J. android怎么用paint实现图像的渐变出现
在android.graphics中提供了有关Gradient字样的类,例如LinearGradient线性渐变、RadialGradient径向渐变和SweepGradient角度渐变三种,他们的基类为android.graphics.Shader。为了演示图像渐变效果,下面给出一个简单的实例。一、LinearGrad