當前位置:首頁 » 安卓系統 » android進度條漸變

android進度條漸變

發布時間: 2022-07-07 01:52:10

1. Android開發怎麼自定義繪制如下圖中這種進度條急需!在線等!

一)變換前背景

先來看看progressbar的屬性:
1. <ProgressBar
2. android:id="@+id/progressBar"
3. style="?android:attr/progressBarStyleHorizontal"
4. android:layout_width="match_parent"
5. android:layout_height="wrap_content"
6. android:layout_margin="5dip"
7. android:layout_toRightOf="@+id/progressBarV"
8. android:indeterminate="false"
9. android:padding="2dip"
10. android:progress="50" />
根據style="?android:attr/progressBarStyleHorizontal",我們找到源碼中的style.xml
1. <style name="Widget.ProgressBar.Horizontal">
2. <item name="android:indeterminateOnly">false</item>
3. <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
4. <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
5. <item name="android:minHeight">20dip</item>
6. <item name="android:maxHeight">20dip</item>
7. </style>
看到
<item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
木有,繼續發掘源碼,找到drawable下面的progress_horizontal.xml,這就是我們今天的主角了:
1. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
2.
3. <item android:id="@android:id/background">
4. <shape>
5. <corners android:radius="5dip" />
6. <gradient
7. android:startColor="#ff9d9e9d"
8. android:centerColor="#ff5a5d5a"
9. android:centerY="0.75"
10. android:endColor="#ff747674"
11. android:angle="270"
12. />
13. </shape>
14. </item>
15.
16. <item android:id="@android:id/secondaryProgress">
17. <clip>
18. <shape>
19. <corners android:radius="5dip" />
20. <gradient
21. android:startColor="#80ffd300"
22. android:centerColor="#80ffb600"
23. android:centerY="0.75"
24. android:endColor="#a0ffcb00"
25. android:angle="270"
26. />
27. </shape>
28. </clip>
29. </item>
30.
31. <item android:id="@android:id/progress">
32. <clip>
33. <shape>
34. <corners android:radius="5dip" />
35. <gradient
36. android:startColor="#ffffd300"
37. android:centerColor="#ffffb600"
38. android:centerY="0.75"
39. android:endColor="#ffffcb00"
40. android:angle="270"
41. />
42. </shape>
43. </clip>
44. </item>
45.
46. </layer-list>
看到android:id="@android:id/progress"木有,看到android:id="@android:id/secondaryProgress"木有
把這個文件復制到自己工程下的drawable,就可以隨心所欲的修改shape的屬性,漸變,圓角等等
那麼怎麼放一個圖片進去呢,ok,新建progress_horizontal1.xml:
1. <?xml version="1.0" encoding="utf-8"?>
2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3.
4. <item android:id="@android:id/progress" android:drawable="@drawable/progressbar" />
5.
6. </layer-list>
在android:drawable中指定你處理好的圖片
然後回到布局中
1. <ProgressBar
2. android:id="@+id/progressBar1"
3. android:layout_width="match_parent"
4. android:layout_height="wrap_content"
5. android:layout_below="@+id/progressBar"
6. android:layout_margin="5dip"
7. android:layout_toRightOf="@+id/progressBarV"
8. android:background="@drawable/progress_bg"
9. android:indeterminate="false"
10. android:indeterminateOnly="false"
11. android:maxHeight="20dip"
12. android:minHeight="20dip"
13. android:padding="2dip"
14. android:progress="50"
15. android:progressDrawable="@drawable/progress_horizontal1" />
android:background="@drawable/progress_bg"指定背景
android:progressDrawable="@drawable/progress_horizontal1"前景使用上面的progress_horizontal1

要是還不行

你來我們群里說吧

這里是開發者互相學習交流的 有大神

讓他們給你解釋你的疑問 號 碼look at my n a m e.....

2. 關於Android怎麼改變ProgressBar進度條顏色

需求:下載中的顏色要自定義,要替換為另外的一個顏色

方法:就是在

<ProgressBar
android:layout_weight="1"
android:id="@+id/download_item_progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="15dip"
android:progressDrawable="@drawable/progressbar_style"></ProgressBar>

在drawable中新建一個progressBar_style.xml文件,

這個屬性進行設置,有兩個方案:

第一,設置兩張圖片:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="">

<item android:id="@android:id/background"
android:drawable="@drawable/progressbar_not" />

<item android:id="@android:id/secondaryProgress"
android:drawable="@drawable/progressbar_not">
</item>

<item android:id="@android:id/progress"
android:drawable="@drawable/progressbar_selected">

</item>
</layer-list>

第二種,設置背景顏色:

<?xml version="1.0" encoding="utf-8"?>
<item android:id="@android:id/background"

>

<shape>

<corners android:radius="5dip" />

<gradient

android:startColor="#666666"

android:centerColor="#666666"

android:centerY="0.75"

android:endColor="#666666"

android:angle="270"

/>

</shape>

</item>

<item android:id="@android:id/progress"

>

<clip>

<shape>

<corners android:radius="5dip" />

<gradient

android:startColor="#da1f3e"

android:centerColor="#da1f3e"

android:centerY="0.75"

android:endColor="#da1f3e"

android:angle="270"

/>

</shape>

</clip>

</item>

<item android:id="@android:id/secondaryProgress"

>

<clip>

<shape>

<corners android:radius="5dip" />

<gradient

android:startColor="#fed7ec"

android:centerColor="#fed7ec"

android:centerY="0.75"

android:endColor="#fed7ec"

android:angle="270"

/>

</shape>

</clip>

</item>

</layer-list>

其中的屬性還要進一步研究具體作用,據文檔翻譯有設置角度,漸變的。
轉載,僅供參考。

3. android漸變設置佔比

比較簡單的一種方式實現顏色漸變,我們通過定製一個對應的shape文件,配置其屬性之後,直接作為android:background賦值給對應的View即可。
1.創建XML文件
在你的drawable文件夾下創建shape資源:
shape_gradient.xml文件代碼如下:
android:endColor="@color/colorPrimary"
android:startColor="@color/colorAccent" />
解釋一下各個層級的標簽:
[shape] 根標簽,聲明一個shape
[gradient] 聲明該shape的屬性-漸變色,除此外還有其他屬性如corners、stroke、size等等
[android:angle]漸變色的角度,舉例來說,0代表從上至下顏色漸變;45代表從左至右顏色漸變;90代表從下至上顏色漸變…
[android:startColor&android:endColor] 很好理解,漸變開始的顏色和漸變結束時的顏色(從什麼顏色變到什麼顏色)
2.將漸變色賦予對應的View
直接放入MainActivity的layout文件中

4. android 進度條樣式 怎麼改

Android系統提供了兩大類進度條樣式,長形進度條(progressBarStyleHorizontal) 和圓形進度條(progressBarStyleLarge)。

android 進度條樣式更改:

  • 第一種

    (默認樣式(中等圓形))

進度條用處很多,比如,應用程序裝載資源和網路連接時,可以提示用戶稍等,這一類進度條只是代表應用程序中某一部分的執行情況,而整個應用程序執行情況呢,則可以通過應用程序標題欄來顯示一個進度條,這就需要先對窗口的顯示風格進行設置"requestWindowFeature(Window.FEATURE_PROGRESS)"。

5. android 繪制進度條

進度條一般是用來顯示耗時操作的,如你圖示,最終完成的時候剛好繞一圈,是一個計時器來確定進度條跑完一圈的時間,然後按時間的流逝來繪制進度條(也就是邊框)。
我的思路是這樣的,首先確定進度條的起始位置,也就是黑色背景圖的上部中間(前提是獲取到背景圖片四個角角位置坐標(X,Y)),計算出圖片的長寬,這樣背景圖片四個角的坐標都有了,進度條的起始坐標也有了,然後根據周長和定時器的時間確定我們每毫秒需要繪制多長,遇到拐角的時候判斷一下進度條的實時坐標與背景圖的拐角坐標是否一致,然後就拐個彎,繼續繪制。
這是個思路,我過會兒調試一下

6. 怎麼在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>

7. android漸變色自定義進度條多大

需求:下載中的顏色要自定義,要替換為另外的一個顏色 方法:就是在 <ProgressBar android:layout_weight="1" android:id="@+id/download_item_progressBar" style="?android:attr/progressBarStyleHorizontal" android:layout_width="wrap_content" android:layout_height="15dip" android:progressDrawable="@drawable/progressbar_style"></ProgressBar> 在drawable中新建一個progressBar_style.xml文件, 這個屬性進行設置,有兩個方案: 第一,設置兩張圖片: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android=""> <item android:id="@android:id/background" android:drawable="@drawable/progressbar_not" /> <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/progressbar_not"> </item> <item android:id="@android:id/progress" android:drawable="@drawable/progressbar_selected"> </item> </layer-list> 第二種,設置背景顏色: <?xml version="1.0" encoding="utf-8"?> <item android:id="@android:id/background" > <shape> <corners android:radius="5dip" /> <gradient android:startColor="#666666" android:centerColor="#666666" android:centerY="0.75" android:endColor="#666666" android:angle="270" /> </shape> </item> <item android:id="@android:id/progress" > <clip> <shape> <corners android:radius="5dip" /> <gradient android:startColor="#da1f3e" android:centerColor="#da1f3e" android:centerY="0.75" android:endColor="#da1f3e" android:angle="270" /> </shape> </clip> </item> <item android:id="@android:id/secondaryProgress" > <clip> <shape> <corners android:radius="5dip" /> <gradient android:startColor="#fed7ec" android:centerColor="#fed7ec" android:centerY="0.75" android:endColor="#fed7ec" android:angle="270" /> </shape> </clip> </item> </layer-list> 其中的屬性還要進一步研究具體作用,據文檔翻譯有設置角度,漸變的。

8. 在android中怎麼至上而下漸變

這個是輸出一層顏色漸變的效果,而你的是多層的,做法一樣,弄幾個小的的三角形同樣的畫法畫到上面。而顏色的值是不可能是線性的值,你只能自己定義每層三角形的顏色,這個是你要做的。 這個我直接用NDK自帶的HELLO-GL2給你弄的,就設置下三角形

9. 求教 android半圓弧形的進度條問題

package com.example.comt;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

public class CircleView extends View {

Paint paint,textpaint;
RectF area;
int value = 100;
LinearGradient shader;

public CircleView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
// TODO Auto-generated constructor stub
}

public CircleView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
// TODO Auto-generated constructor stub
}

public CircleView(Context context) {
super(context);
init();
// TODO Auto-generated constructor stub
}

public void setProgress(int value){
this.value = value;
invalidate();
}

public void init() {
paint = new Paint();
paint.setStrokeWidth(50f);
paint.setColor(Color.WHITE);
paint.setStyle(Style.STROKE);
paint.setAntiAlias(true);
textpaint = new Paint();
textpaint.setTextSize(50f);
textpaint.setColor(Color.WHITE);
area = new RectF(100, 100, 500, 500);

shader =new LinearGradient(0, 0, 400, 0, new int[] {
Color.BLUE, Color.WHITE}, null,
Shader.TileMode.CLAMP);
paint.setShader(shader);

}

@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.drawColor(Color.GRAY);
canvas.drawArc(area, 120, 360*value/100 , false, paint);
canvas.drawText(value+"%", 270, 290, textpaint);
}

}

看下是不是你想要的,調用setprogress()既可調節圓環

10. 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>

效果:

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:627
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:356
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:73
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:297
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:787
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:337
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:202
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:800
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:356
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:582