當前位置:首頁 » 安卓系統 » 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 屬性。

熱點內容
艾莫迅plc編程電纜 發布:2025-03-15 20:44:05 瀏覽:301
妖妖靈腳本 發布:2025-03-15 20:36:56 瀏覽:254
公司自己搭建ftp 發布:2025-03-15 20:36:07 瀏覽:61
如何增加配置使半袖變得不單調 發布:2025-03-15 20:33:37 瀏覽:349
linux顯示目錄 發布:2025-03-15 20:30:42 瀏覽:660
素數演算法表示 發布:2025-03-15 20:24:02 瀏覽:842
大話西遊手游怎麼看伺服器等級 發布:2025-03-15 20:21:53 瀏覽:221
rsa加密c源代碼 發布:2025-03-15 19:53:55 瀏覽:693
linux解壓bin 發布:2025-03-15 19:40:25 瀏覽:384
存儲數據為什麼只能使用兩種狀態 發布:2025-03-15 19:40:21 瀏覽:264