導航:首頁 > 操作系統 > android自定義進度條圖片

android自定義進度條圖片

發布時間:2022-09-26 13:43:09

android自定義環形進度條怎麼自由控制進度條的消失與隱藏

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bluetoothmeter);
mhandler = new Handler();

//通過mSearcheHandler更新UI
mSearchHandler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what==0){
//改變環形進度條的進度
mCircleProcessBar.setProgress(mcnt);
mcnt+=1;
if(MCNT_MAX<=mcnt){
mCircleProcessBar.setVisibility(View.GONE);
}
}
}
};
mBlueService = BluetoothLeService.getInstance();
initView();
initEvent();
}

private void initEvent()
{
mImgBtnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
//搜索
mbtnSearch.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// Prepare list view and initiate scanning
if (m_devicelistadapter != null) {
m_devicelistadapter.clear();
m_devicelistadapter.notifyDataSetChanged();

}
startScan();

//設置圓環進度條的出現時間(秒)
new TimerDelay(mSearchHandler).setDelayTime(CIRCLE_APPARE_TIME,mCircleProcessBar);
mcnt=1;
}
});
}

❷ 關於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>

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

❸ android布局文件里的ProgressBar長形進度條怎麼自定義樣式

在windows操作系統下Android studio按照如下步驟自動義ProgressBar長形進度條的樣式。

1、首先創建一個android項目,打開其中的XML布局文件,如下圖:

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

❺ 長按如何使進度條變化Android

通過MediaPlayer調節。
系統自帶的進度條的顏色比較單調,實際開發中使用較少,可以自定義進度條背景,新建一個progressbarbg.xml文件。gradient可以設置進度條的漸變色,android:endColor和android:startColor可以設置漸變開始和結束的顏色。定義完成以後,便可以使用。
在音樂進度,網路下載時,需動態載入進度條,默認情況下,設置進度條,使用setProgress即可。但有時除了動態設置進度,仍需要動態設置進度條顏色通過MediaPlayer播放音樂並獲取進度,設置進度。

❻ android自定義progressbar圖片大小自適應

通過animation-list 動畫自定義的progressbar樣式,如果progressbar設置的長度和寬度超過了動畫中圖片的大小,效果會很難看,通過如下方式可解決。 <animation-list xmlns:android="

❼ 自定義progressdialog怎麼setmessage

Android SDK已經提供有進度條組件ProgressDialog組件,但用的時候我們會發現可能風格與我們應用的整體風格不太搭配,而且ProgressDialog的可定製行也不太強,這時就需要我們自定義實現一個ProgressDialog。
通過看源碼我們發現,ProgressDialog繼承自Alertdialog,有一個ProgressBar和兩個TextView組成的,通過對ProgressDialog的源碼進行改進就可以實現一個自定義的ProgressDialog。

1、效果:

首先看一下自定義CommonProgressDialog和原生ProgressDialog的對比:


2、代碼:

common_progress_dialog.xml 布局文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="798px"
android:layout_height="460px"
android:orientation="vertical"
android:background="@drawable/common_progress_dialog_background">
<TextView
android:id="@+id/progress_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="44px"
android:layout_marginTop="113px"
android:layout_gravity="center_horizontal"
android:textColor="#ffffff"
/>
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="712px"
android:layout_height="30px"
android:layout_marginTop="100px"
android:layout_marginLeft="47px"
android:layout_centerHorizontal="true"
android:progressDrawable="@drawable/common_progressdialog_progressbar_background"
/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/progress_percent"
android:layout_width="80px"
android:layout_height="wrap_content"
android:textSize="30px"
android:layout_marginLeft="280px"
android:gravity="center_horizontal"
android:textColor="#ffffff"
/>
<TextView
android:id="@+id/progress_number"
android:layout_width="250px"
android:layout_height="wrap_content"
android:layout_marginLeft="120px"
android:textSize="30px"
android:gravity="center_horizontal"
android:textColor="#ffffff"
/>
</LinearLayout>
</LinearLayout>
</FrameLayout>

common_progressdialog_progressbar_background.xml Progressbar進度條圖片和背景圖片設置

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="@android:id/background"
android:drawable="@drawable/common_progress_dialog_progressbar3"
/>
<item
android:id="@android:id/progress"
android:drawable="@drawable/common_progress_dialog_progressbar2"
/>

</layer-list>

CommonProgressDialog.java類:

package com.johnny.testactivity;


import java.text.NumberFormat;


import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;


public class CommonProgressDialog extends AlertDialog {


private ProgressBar mProgress;
private TextView mProgressNumber;
private TextView mProgressPercent;
private TextView mProgressMessage;

private Handler mViewUpdateHandler;
private int mMax;
private CharSequence mMessage;
private boolean mHasStarted;
private int mProgressVal;

private String TAG="CommonProgressDialog";
private String mProgressNumberFormat;
private NumberFormat mProgressPercentFormat;
public CommonProgressDialog(Context context) {
super(context);
// TODO Auto-generated constructor stub
initFormats();
}


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.common_progress_dialog);
mProgress=(ProgressBar) findViewById(R.id.progress);
mProgressNumber=(TextView) findViewById(R.id.progress_number);
mProgressPercent=(TextView) findViewById(R.id.progress_percent);
mProgressMessage=(TextView) findViewById(R.id.progress_message);
// LayoutInflater inflater = LayoutInflater.from(getContext());
mViewUpdateHandler = new Handler() {


@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
int progress = mProgress.getProgress();
int max = mProgress.getMax();
double dProgress = (double)progress/(double)(1024 * 1024);
double dMax = (double)max/(double)(1024 * 1024);
if (mProgressNumberFormat != null) {
String format = mProgressNumberFormat;
mProgressNumber.setText(String.format(format, dProgress, dMax));
} else {
mProgressNumber.setText("");
}
if (mProgressPercentFormat != null) {
double percent = (double) progress / (double) max;
SpannableString tmp = new SpannableString(mProgressPercentFormat.format(percent));
tmp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),
0, tmp.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mProgressPercent.setText(tmp);
} else {
mProgressPercent.setText("");
}
}

};
// View view = inflater.inflate(R.layout.common_progress_dialog, null);
// mProgress = (ProgressBar) view.findViewById(R.id.progress);
// mProgressNumber = (TextView) view.findViewById(R.id.progress_number);
// mProgressPercent = (TextView) view.findViewById(R.id.progress_percent);
// setView(view);
//mProgress.setMax(100);
onProgressChanged();
if (mMessage != null) {
setMessage(mMessage);
}
if (mMax > 0) {
setMax(mMax);
}
if (mProgressVal > 0) {
setProgress(mProgressVal);
}
}
private void initFormats() {
mProgressNumberFormat = "%1.2fM/%2.2fM";
mProgressPercentFormat = NumberFormat.getPercentInstance();
mProgressPercentFormat.setMaximumFractionDigits(0);
}
private void onProgressChanged() {
mViewUpdateHandler.sendEmptyMessage(0);


}
public void setProgressStyle(int style) {
//mProgressStyle = style;
}
public int getMax() {
if (mProgress != null) {
return mProgress.getMax();
}
return mMax;
}
public void setMax(int max) {
if (mProgress != null) {
mProgress.setMax(max);
onProgressChanged();
} else {
mMax = max;
}
}
public void setIndeterminate(boolean indeterminate) {
if (mProgress != null) {
mProgress.setIndeterminate(indeterminate);
}
// else {
// mIndeterminate = indeterminate;
// }
}
public void setProgress(int value) {
if (mHasStarted) {
mProgress.setProgress(value);
onProgressChanged();
} else {
mProgressVal = value;
}
}


@Override
public void setMessage(CharSequence message) {
// TODO Auto-generated method stub
//super.setMessage(message);
if(mProgressMessage!=null){
mProgressMessage.setText(message);
}
else{
mMessage = message;
}
}


@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
mHasStarted = true;
}


@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
mHasStarted = false;
}

}

測試程序:

private void showDialog(){
mDialog = new CommonProgressDialog(this);

mDialog.setMessage("正在下載");
mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mDialog.setOnCancelListener(new OnCancelListener() {

@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
//cancel(true);
}
});
mDialog.show();

mDialog.setMax(100*1024*1024);
mDialog.setProgress(65*1024*1024);
}

❽ android 怎麼自定義繪制如下圖中這種進度條

下面是安卓學習手冊中實現各種進度條的截圖:

要想看各種進度條的實現代碼和文檔,直接去360手機助手中下載安卓學習手冊,例子文檔隨便看。

1、說明

在某些操作的進度中的可視指示器,為用戶呈現操作的進度,還它有一個次要的進度條,用來顯示中間進度,如在流媒體播放的緩沖區的進度。一個進度條也可不確定其進度。在不確定模式下,進度條顯示循環動畫。這種模式常用於應用程序使用任務的長度是未知的。

2、XML重要屬性

android:progressBarStyle:默認進度條樣式

android:progressBarStyleHorizontal:水平樣式

3 重要方法

getMax():返回這個進度條的范圍的上限

getProgress():返回進度

getSecondaryProgress():返回次要進度

incrementProgressBy(int diff):指定增加的進度

isIndeterminate():指示進度條是否在不確定模式下

setIndeterminate(boolean indeterminate):設置不確定模式下

setVisibility(int v):設置該進度條是否可視

4 重要事件

onSizeChanged(int w, int h, int oldw, int oldh):當進度值改變時引發此事件

5進度條的樣式

Widget.ProgressBar.Horizontal長形進度

Androidxml 布局:

<ProgressBar

android:id="@+id/progress_bar"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

style="@android:style/Widget.ProgressBar.Horizontal "

/>

源碼:

private ProgressBar mProgress;

private int mProgressStatus=0;

private Handler mHandler=newHandler();

@Override

protected void onCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mProgress=(ProgressBar)findViewById(R.id.progress_bar);

new Thread(new Runnable(){

@Override

public void run(){

while(mProgressStatus<100){

mProgressStatus=doWork();

mHandler.post(new Runnable(){

@Override

public void run(){

mProgress.setProgress(mProgressStatus);

}

});

}

}

}).start();

}

效果圖:

帶第二進度的進度條

xml配置如下:

<ProgressBar

android:id="@+id/progress_bar_with_second"

style="@android:style/Widget.ProgressBar.Horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:progress="40"

android:secondaryProgress="70"

android:paddingTop="20dp"

android:paddingBottom="20dp"/>

這里我們設置了初始的進度為40,android:progress的值在mini和max之間即mini<=progressvalue<=max

設置了第二進度條的進度值為70,該值也在mini和max之間。

效果如下:

不確定模式進度條

xml配置文件:

<ProgressBar

android:id="@+id/progress_bar_indeterminate"

style="@android:style/Widget.ProgressBar.Horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:indeterminate="true"

android:indeterminateBehavior="cycle"

android:paddingBottom="20dp"

android:paddingTop="20dp"

android:progress="40" />

這里通過android:indeterminate="true"設置了當前為無模式進度條

效果如圖:

普通圓形進度:Widget.ProgressBar.Inverse

<ProgressBar

android:id="@+id/progress_bar1"

style="@android:style/Widget.ProgressBar.Inverse"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:progress="50"

android:background="#ff00ff"

android:paddingTop="4dp" />

通過android:backgroup設置了背景色

❾ Android自定義RatingBar(星級評分控制項)

RatingBar是基於SeekBar(拖動條)和ProgressBar(狀態條)的擴展,用星形來顯示等級評定!

RatingBar實現的效果圖:

      看著自定義的樣式遠遠比Android自帶的樣式好看多了,用戶體驗度遠遠提升,下面我們就來實現該控制項:

  定義根據圖片自定一個RatingBar的背景條,和圖片放到同一個目錄下面

     five_rating_bar.xml

backgroud:是用來填充背景圖片的,和進度條非常類似,當我們設置最高評分時(android:numStars),系統就會根據我們的設置,來畫出以星星為單位的背景(假如android:numStars="5",就會畫出5顆灰色的星星)

progress:是用來在背景圖片基礎上進行填充的指示屬性(和進度條類似,第一進度位置)

secondaryProgress:同progress一樣屬於第二進度位置(如果不定義這個,進度條拖動,每次就畫出一整顆星星(亮),第二進度(暗)沒有覆蓋掉第一進度之後的位置,從左往右是拖不出來N.5顆星星的,這樣評分效果就不完整)

    style.xml

      提取樣式屬於個人習慣,這里可以不提取出來,可以寫在布局文件中,這里RatingBar的樣式是通過style來切換的。

    通過 parent屬性來選擇繼承的父類,我們這里繼承RatingBar類。

    重新定義 progressDrawable屬性(RatingBar的背景條)

    maxHeight和minHeight可以根據我們圖片像素或者其他參考值來設定。

在我們需要用到RatingBar的xml配置文件裡面添加RatingBar控制項。

     main.xml

android:isIndicator              RatingBar是否是一個指示器(用戶無法進行更改)

android:numStars               顯示的星型數量,必須是一個整形值,像「100」。

android:rating                    默認的評分,必須是浮點類型,像「1.2」。

android:stepSize                 評分的步長,必須是浮點類型,像「1.2」。

就這么簡單,我們自定義屬於自己的RatingBar,星級評分控制項!

閱讀全文

與android自定義進度條圖片相關的資料

熱點內容
優化演算法的輸入維數越不容易收斂 瀏覽:777
java極限編程pdf 瀏覽:130
塞葡萄的是哪個小說 瀏覽:821
架設傳奇命令 瀏覽:951
關於醫生的小說 瀏覽:520
愛情動作電影 瀏覽:808
八零電子書txt免費下載網站 瀏覽:509
登陸遼事通顯示伺服器連接錯誤怎麼辦 瀏覽:547
9米高隧道演算法 瀏覽:508
池袋最強作品集txt 瀏覽:784
app專題推薦在哪裡 瀏覽:279
神雲伺服器顯示燈 瀏覽:134
程序員磨合期技巧 瀏覽:849
鬼團六全部電影名稱 瀏覽:864
穿越唯一一個女人世界 瀏覽:645
飛言情小說官網入口 瀏覽:581
pdf壓縮後還清晰嗎 瀏覽:654
得到app的電子書書架在哪裡 瀏覽:151
管道彎頭製作演算法 瀏覽:37
phpmvcsmarty實例 瀏覽:925