当前位置:首页 » 安卓系统 » android渐变圆

android渐变圆

发布时间: 2022-12-09 07:58:35

⑴ android怎么设置字体渐变色 不是背景渐变

●使用XML的方式为背景添加渐变效果
1、在res/drawable文件夹里添加一个jbshape.xml文件,然后写入如下代码:
<?xml version="1.0" encoding="utf-8"?>

<gradient
android:angle="270"
android:centerColor="#00FFFF"
android:centerX="0.5"
android:centerY="0.5"
android:endColor="#666666"
android:startColor="#0099FF" />

<padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp" />

<corners android:radius="4dp" />

</shape>
说明:
(1)shape节点配置的是图形的形式,主要包括方形、圆形等,上边代码为方形。
(2)gradient节点主要配置起点颜色、终点颜色及中间点的颜色、坐标、渐变效果(0,90,180从左到右渐变,270从上到下渐变)默认从左到右。
(3)corners节点配置四周圆角的半径。

⑵ 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>

效果:

⑶ Android studio中怎么将方形按钮设置成圆角以及渐变效果

一、在 studio中res 包下的drawable中建立一个shape的文件,系统会给你一个默认的方形然后你就可以开始设置你需要的效果。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:Android="http://schemas.android.com/apk/res/android">

<!--填充背景色 -->
<solid android:color="#ffff00" /> //solid 指的是背景颜色的设置

<!--描边 他需要 2个参数,颜色 第二参数 宽度 -->
<stroke
android:width="2dp" //width 指的是边框的宽度
android:color="#ff00ff" /> //color指的是边框的颜色

<!-- 设置弧度 Radius设置所有角的弧度 --> //radius 指的就是角的弧度
<corners //方形存在四个角,我们可以同时设置四个角,也可以分开设置
android:bottomLeftRadius="20dp" //左下角
android:bottomRightRadius="20dp" //右下角
android:topLeftRadius="20dp" //左上角
android:topRightRadius="20dp" /> //右上角

//同时设置:<corners
android:Radius="20dp" /> //四个角同时设置

<!-- 渐变色 startColor 启示颜色 endColor最终颜色 type类型(如果类型为radial(径向渐变,一个圆心以半径的方式渐变),必须加上 android:gradientRadius="**")-->
<gradient
android:startColor="#ff0000" //开始颜色
android:endColor="#ffffff" //结束颜色
android:type="linear" /> //水平渐变 从左到右 type 指的是渐变的模式

<!--内容与边框的间距-->
<padding
android:bottom="15dp"
android:left="15dp"
android:right="15dp"
android:top="15dp" />

<!--如果设置了渐变色 那么背景颜色将不显示 -->

</shape>
<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绘图之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

⑸ 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游戏开发的基础很有好处。

⑹ 怎么在android上面做出根据形状来渐变的效果

<shape> Android:shape=["rectangle" | "oval" | "line" | "ring"] 其中rectagle矩形,oval椭圆,line水平直线,ring环形
<shape>中子节点的常用属性:
<gradient> 渐变
Android:startColor 起始颜色
Android:endColor 结束颜色
Android:angle 渐变角度,0从左到右,90表示从下到上,数值为45的整数倍,默认为0;
Android:type 渐变的样式 liner线性渐变 radial环形渐变 sweep <solid > 填充
Android:color 填充的颜色
<stroke >描边
Android:width 描边的宽度
Android:color 描边的颜色
Android:dashWidth 表示'-'横线的宽度
Android:dashGap 表示'-'横线之间的距离
<corners >圆角
Android:radius 圆角的半径 值越大角越圆
Android:topRightRadius 右上圆角半径
Android:bottomLeftRadius 右下圆角角半径
Android:topLeftRadius 左上圆角半径
Android:bottomRightRadius 左下圆角半径
<padding >填充
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/文件的名称"
示例:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:Android="http://schemas.android.com/apk/res/android">
<!-- 默认时的背景图片-->
<item Android:drawable="@drawable/pic1" />
<!-- 没有焦点时的背景图片 -->
<item
Android:state_window_focused="false"
android:drawable="@drawable/pic_blue"
/>
<!-- 非触摸模式下获得焦点并单击时的背景图片 -->
<item
Android:state_focused="true"
android:state_pressed="true"
android:drawable= "@drawable/pic_red"
/>
<!-- 触摸模式下单击时的背景图片-->
<item
Android:state_focused="false"
Android:state_pressed="true"
Android:drawable="@drawable/pic_pink"
/>
<!--选中时的图片背景-->
<item
Android:state_selected="true"
android:drawable="@drawable/pic_orange"
/>
<!--获得焦点时的图片背景-->
<item
Android:state_focused="true"
Android:drawable="@drawable/pic_green"
/>
</selector>

layer-list(多个shape)
将多个图片或上面两种效果按照顺序层叠起来
示例:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/android_red"
android:gravity="center" />
</item>
<item android:top="10dp" android:left="10dp">
<bitmap android:src="@drawable/android_green"
android:gravity="center" />
</item>
<item android:top="20dp" android:left="20dp">
<bitmap android:src="@drawable/android_blue"
android:gravity="center" />
</item>
</layer-list>

感觉很像多个drawable
三者可以结合使用
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item android:bottom="8.0dip">
<shape>
<solid android:color="#ffaaaaaa" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="4.0dip" android:bottomRightRadius="4.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="#ffaaaaaa" />

<padding android:bottom="1.0dip" android:left="1.0dip" android:right="1.0dip" android:top="0.0dip" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="3.0dip" android:bottomRightRadius="3.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="@color/setting_item_bgcolor_press" />
</shape>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item android:bottom="8.0dip">
<shape>
<solid android:color="#ffaaaaaa" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="4.0dip" android:bottomRightRadius="4.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="#ffaaaaaa" />

<padding android:bottom="1.0dip" android:left="1.0dip" android:right="1.0dip" android:top="0.0dip" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="3.0dip" android:bottomRightRadius="3.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="@color/setting_item_bgcolor" />
</shape>
</item>
</layer-list>
</item>
</selector>

⑺ 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角度渐变三种。

⑻ Android View — Gradient 渐变

Android 支持三种颜色渐变, LinearGradient(线性渐变) RadialGradient (径向渐变) SweepGradient(扫描渐变)。这三种渐变继承自android.graphics.Shader, Paint 类通过setShader支持渐变。

线性渐变就是在线性方向的的渐变。有两个构造函数,

第二种 构造函数是第一种的简化版,只支持两种颜色。

RadialGradient 是圆环一样的的渐变,RadialGradient 同样是两个构造函数,

1.float centerX, float centerY 渐变的中心点 圆心
2.float radius 渐变的半径
3.int[] colors 渐变颜色数组
4.float[] stops 和颜色数组对应, 每种颜色在渐变方向上所占的百分比取值[0, 1]
5.Shader.TileMode tileMode 表示绘制完成,还有剩余空间的话的绘制模式。

1.float centerX, float centerY 渐变的中心点 圆心
2.float radius 渐变的半径
3.int centerColor, int edgeColor 中心点颜色和边缘颜色
4.Shader.TileMode tileMode 表示绘制完成,还有剩余空间的话的绘制模式

SweepGradient 是和角度有关的渐变。以某一点为圆心,随着角度的大小发生渐变。

1.float cx, float cy 中心点坐标
2.int[] colors 颜色数组
3.float[] positions 数组颜色在渐变方向上所占的百分比

1.float cx, float cy 中心点坐标
2.int color0, int color1 开始颜色 结束颜色

在LinearGradient RadialGradient 渐变中,构造函数的最后一个参数为 Shader.TileMode 类型,决定了如果View还有剩余空间,如何绘制。

从上到下依次为:CLAMP REPEAT MIRROR

从上到下依次为:CLAMP REPEAT MIRROR

一些背景的渐变通过定义 Shape Drawable 来实现。Shape Drawable 有gradient 属性。

热点内容
linuxpython命令行 发布:2025-03-15 16:19:45 浏览:958
编译androidx86 发布:2025-03-15 16:19:01 浏览:785
戴尔g15怎么切换温度配置文件 发布:2025-03-15 16:16:18 浏览:850
长江存储0 发布:2025-03-15 16:15:35 浏览:46
地狱边境安卓版不支持谷歌怎么办 发布:2025-03-15 16:15:32 浏览:161
kld数据库 发布:2025-03-15 15:46:27 浏览:263
互联网数据库设计 发布:2025-03-15 15:44:42 浏览:240
自适应滤波c语言 发布:2025-03-15 15:40:25 浏览:969
cs狙击脚本 发布:2025-03-15 15:25:15 浏览:344
平板搭建ftp服务器 发布:2025-03-15 15:24:32 浏览:832