導航:首頁 > 操作系統 > android控制進度條

android控制進度條

發布時間:2022-09-26 00:43:54

A. 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;
}
});
}

B. android studio怎麼把進度條的值取出來

本文實例為大家分享了Android Studio實現進度條效果的具體代碼,供大家參考,具體內容如下:

xml代碼


xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context=".ProgressBarActivity">


android:id="@+id/pb_determinate"

android:layout_width="match_parent"

android:layout_height="wrap_content"

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

android:backgroundTint="@color/purple_200"

android:progress="25"

android:max="100"

android:layout_centerVertical="true"

/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="ProgressBar"

android:textSize="28sp"

android:gravity="center"

android:layout_below="@+id/pb_determinate"

C. android編程里如何使用按鈕來增加和減少進度條的進度

java">//這個是增加的,把這看懂,減的也就會了
packagecom.example.progressbardemo;

importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.ProgressBar;

{

privateProgressBarone;
privateButtonbutton;
privateinti=0;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
one=(ProgressBar)findViewById(R.id.progressBar2);
button=(Button)findViewById(R.id.button1);
button.setOnClickListener(newOnClickListener(){

@Override
publicvoidonClick(Viewarg0){
if(i==0){
one.setVisibility(View.VISIBLE);
}
elseif(i<one.getMax())
{
one.setProgress(i);
}
else
{
one.setVisibility(View.GONE);
i=0;
}
i+=5;
}
});
}



}

D. 安卓怎麼在在對話框中 搞一個進度條

方法/步驟:
單擊按鈕,彈出對話框,對話框中有進度條!
下面 來實現這個功能了

新建一個android工程,定義好xml 只需要一個button就可以了
在MainAtvity中,定義
ProgressDialog m_pDialog;

創建單擊響應事件
在OncliView中可以
m_pDialog = new ProgressDialog(MainActivity.this);

// 設置進度條風格,風格為圓形,旋轉的

m_pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

// 設置ProgressDialog 標題

m_pDialog.setTitle("提示");

// 設置ProgressDialog 提示信息

m_pDialog.setMessage("這是一個圓形進度條對話框");

// 設置ProgressDialog 標題圖標

// 設置ProgressDialog 的進度條是否不明確

m_pDialog.setIndeterminate(false);

// 設置ProgressDialog 是否可以按退回按鍵取消

m_pDialog.setCancelable(true);
m_pDialog.show();
4
完成,單擊按鈕 就可以彈出對話框,(包含進度條~~)

E. 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設置了背景色

F. android網路載入進度條怎麼使用

由於Android的界面更新只能通過自己的UI線程進行操作,所以我們需要用到Handler在進行更新界面的操作。

1、聲明變數
private Handler handler = new Handler();
private ProgressDialog progressDialog = null;

2、在開始進行網路連接時顯示進度條對話框
progressDialog = ProgressDialog.show(MyActivity.this, "請稍等...", "獲取數據中...", true);

3、在handler.post中進行界面更新
public void setListAdapter(){
handler.post(new Runnable() {
public void run() {
//將獲取到的數據更新到列表中
MyListView.setAdapter(saImageItems);
}
}
});

4、開個新的線程進行網路連接獲取數據
new Thread(new Runnable(){

@Override
public void run() {
// TODO Auto-generated method stub
//向伺服器請求數據
mapList=MyAPI.getAllDatas();
setListAdapter(mapList);
//更新完列表數據,則關閉對話框
progressDialog.dismiss();
}}).start();

整個過程就這樣完成了,下面是效果圖:

G. android 進度條樣式 怎麼改

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

android 進度條樣式更改:

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

H. android 繪制進度條

看起來代碼挺長,其實都是在獲取自定義屬性,沒什麼技術含量。
寬度不變,所以的自定義屬性不涉及寬度,高度呢,只考慮不是EXACTLY的情況(用戶明確指定了,就不管了),根據padding和進度條寬度算出自己想要的,如果非EXACTLY下,進行exceptHeight封裝,傳入給控制項進行測量高度。

橫向的滾動條繪制肯定需要一些屬性,比如已/未到達進度的顏色、寬度,文本的顏色、大小等。
本來呢,我是想通過系統ProgressBar的progressDrawable,從裡面提取一些屬性完成繪制需要的參數的。但是,最終呢,反而讓代碼變得復雜。所以最終還是改用自定義屬性。 說道自定義屬性,大家應該已經不陌生了。

1、
1、自定義屬性
values/attr_progress_bar.xml:

[html] view plain
<?xml version="1.0" encoding="utf-8"?>
<resources>

<declare-styleable name="">
<attr name="progress_unreached_color" format="color" />
<attr name="progress_reached_color" format="color" />
<attr name="progress_reached_bar_height" format="dimension" />
<attr name="progress_unreached_bar_height" format="dimension" />
<attr name="progress_text_size" format="dimension" />
<attr name="progress_text_color" format="color" />
<attr name="progress_text_offset" format="dimension" />
<attr name="progress_text_visibility" format="enum">
<enum name="visible" value="0" />
<enum name="invisible" value="1" />
</attr>
</declare-styleable>

<declare-styleable name="RoundProgressBarWidthNumber">
<attr name="radius" format="dimension" />
</declare-styleable>

</resources>
2、構造中獲取

[java] view plain
public class extends ProgressBar
{

private static final int DEFAULT_TEXT_SIZE = 10;
private static final int DEFAULT_TEXT_COLOR = 0XFFFC00D1;
private static final int DEFAULT_COLOR_UNREACHED_COLOR = 0xFFd3d6da;
private static final int DEFAULT_HEIGHT_REACHED_PROGRESS_BAR = 2;
private static final int DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR = 2;
private static final int DEFAULT_SIZE_TEXT_OFFSET = 10;

/**
* painter of all drawing things
*/
protected Paint mPaint = new Paint();
/**
* color of progress number
*/
protected int mTextColor = DEFAULT_TEXT_COLOR;
/**
* size of text (sp)
*/
protected int mTextSize = sp2px(DEFAULT_TEXT_SIZE);

/**
* offset of draw progress
*/
protected int mTextOffset = dp2px(DEFAULT_SIZE_TEXT_OFFSET);

/**
* height of reached progress bar
*/
protected int mReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_REACHED_PROGRESS_BAR);

/**
* color of reached bar
*/
protected int mReachedBarColor = DEFAULT_TEXT_COLOR;
/**
* color of unreached bar
*/
protected int mUnReachedBarColor = DEFAULT_COLOR_UNREACHED_COLOR;
/**
* height of unreached progress bar
*/
protected int mUnReachedProgressBarHeight = dp2px(DEFAULT_HEIGHT_UNREACHED_PROGRESS_BAR);
/**
* view width except padding
*/
protected int mRealWidth;

protected boolean mIfDrawText = true;

protected static final int VISIBLE = 0;

public (Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}

public (Context context, AttributeSet attrs,
int defStyle)
{
super(context, attrs, defStyle);

setHorizontalScrollBarEnabled(true);

obtainStyledAttributes(attrs);

mPaint.setTextSize(mTextSize);
mPaint.setColor(mTextColor);

}

/**
* get the styled attributes
*
* @param attrs
*/
private void obtainStyledAttributes(AttributeSet attrs)
{
// init values from custom attributes
final TypedArray attributes = getContext().obtainStyledAttributes(
attrs, R.styleable.);

mTextColor = attributes
.getColor(
R.styleable._progress_text_color,
DEFAULT_TEXT_COLOR);
mTextSize = (int) attributes.getDimension(
R.styleable._progress_text_size,
mTextSize);

mReachedBarColor = attributes
.getColor(
R.styleable._progress_reached_color,
mTextColor);
mUnReachedBarColor = attributes
.getColor(
R.styleable._progress_unreached_color,
DEFAULT_COLOR_UNREACHED_COLOR);
mReachedProgressBarHeight = (int) attributes
.getDimension(
R.styleable._progress_reached_bar_height,
mReachedProgressBarHeight);
mUnReachedProgressBarHeight = (int) attributes
.getDimension(
R.styleable._progress_unreached_bar_height,
mUnReachedProgressBarHeight);
mTextOffset = (int) attributes
.getDimension(
R.styleable._progress_text_offset,
mTextOffset);

int textVisible = attributes
.getInt(R.styleable._progress_text_visibility,
VISIBLE);
if (textVisible != VISIBLE)
{
mIfDrawText = false;
}
attributes.recycle();
}

3、onMeasure
剛才不是出onDraw裡面寫寫就行了么,為什麼要改onMeasure呢,主要是因為我們所有的屬性比如進度條寬度讓用戶自定義了,所以我們的測量也得稍微變下。

[java] view plain
@Override
protected synchronized void onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
{
int heightMode = MeasureSpec.getMode(heightMeasureSpec);

if (heightMode != MeasureSpec.EXACTLY)
{

float textHeight = (mPaint.descent() + mPaint.ascent());
int exceptHeight = (int) (getPaddingTop() + getPaddingBottom() + Math
.max(Math.max(mReachedProgressBarHeight,
mUnReachedProgressBarHeight), Math.abs(textHeight)));

heightMeasureSpec = MeasureSpec.makeMeasureSpec(exceptHeight,
MeasureSpec.EXACTLY);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

}

測量完,就到我們的onDraw了~~~

I. android 怎麼使水平進度條動起來 最好有個例子 我是新手

進度條的操作你應該會的吧。
例子網上其實有很多,我大致說一下。

首先你要寫一個線程,然後循環i從1開始,i++,一直到100
然後去修改你主線程的進度條
這樣你的進度條就動起來了!當到100的時候,傳一個intent 跳轉activity

J. android 進度條

頂部放一個ProgressBar或者ImageView,進入的時候開始轉圈,轉完了就隱藏起來,view.setVisibility(View.INVISIBLE);再把其他界面顯示出來就好了,view.setVisibility(View.VISIBLE);

閱讀全文

與android控制進度條相關的資料

熱點內容
程序員求助國企 瀏覽:837
雲伺服器網址租用多少錢 瀏覽:942
行車記錄儀安卓版怎麼用 瀏覽:500
java是不是數字 瀏覽:182
php模擬瀏覽器環境 瀏覽:353
編程誰都能學會嗎 瀏覽:407
使用國家反詐app都要開啟什麼 瀏覽:712
下載民宿APP有什麼用 瀏覽:52
續子語pdf 瀏覽:385
2021年加密貨幣最新行情 瀏覽:162
nfs怎麼加密ipsec 瀏覽:245
國二考試調用編譯器運算選擇題 瀏覽:750
同濟大學高等數學pdf 瀏覽:234
延時的宏命令怎麼設置 瀏覽:596
資料庫有哪些加密 瀏覽:209
改之理反編譯注冊教程 瀏覽:391
什麼是編譯程序和翻譯程序 瀏覽:208
python課程心得總結 瀏覽:17
派派中怎麼看對方在哪個伺服器 瀏覽:796
xp配置java環境變數配置 瀏覽:9