當前位置:首頁 » 安卓系統 » android進度百分比

android進度百分比

發布時間: 2022-08-15 04:52:33

A. android進度條怎麼顯示百分比

顯示百分比需要自己計算載入的內容,以下以webView示例,webView載入網頁的時候可以增加進度條:
1.從webView中獲取設置
WebSettings sws = webView.getSettings();
sws.setSupportZoom(true);
sws.setBuiltInZoomControls(true);
webView.setInitialScale(25);
webView.getSettings().setUseWideViewPort(true);

2.注冊setWebChromeClient事件
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activity和Webview根據載入程度決定進度條的進度大小
// 當載入到100%的時候 進度條自動消失
//WebViewProgressActivity.this.setTitle("Loading...");
//WebViewProgressActivity.this.setProgress(progress * 100);
if (progress == 100) {
progressBar.setVisibility(View.GONE);
//WebViewProgressActivity.this.setTitle("完成");
}
}
});

3.注意在onProgressChanged中處理進度,progress就是進度值。

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

package com.example.roundprogressbar;import android.content.Context;import android.content.res.TypedArray;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.RectF;import android.graphics.Typeface;import android.util.AttributeSet;import android.util.Log;import android.view.View;import com.example.circlepregress.R;/** * 仿iphone帶進度的進度條,線程安全的View,可直接在線程中更新進度 * @author xiaanming * */public class RoundProgressBar extends View {/*** 畫筆對象的引用*/private Paint paint;/*** 圓環的顏色*/private int roundColor;/*** 圓環進度的顏色*/private int roundProgressColor;/*** 中間進度百分比的字元串的顏色*/private int textColor;/*** 中間進度百分比的字元串的字體*/private float textSize;/*** 圓環的寬度*/private float roundWidth;/*** 最大進度*/private int max;/*** 當前進度*/private int progress;/*** 是否顯示中間的進度*/private boolean textIsDisplayable;/*** 進度的風格,實心或者空心*/private int style;public static final int STROKE = 0;public static final int FILL = 1;public RoundProgressBar(Context context) {this(context, null);}public RoundProgressBar(Context context, AttributeSet attrs) {this(context, attrs, 0);}public RoundProgressBar(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);paint = new Paint();TypedArray mTypedArray = context.obtainStyledAttributes(attrs,R.styleable.RoundProgressBar);//獲取自定義屬性和默認值roundColor = mTypedArray.getColor(R.styleable.RoundProgressBar_roundColor, Color.RED);roundProgressColor = mTypedArray.getColor(R.styleable.RoundProgressBar_roundProgressColor, Color.GREEN);textColor = mTypedArray.getColor(R.styleable.RoundProgressBar_textColor, Color.GREEN);textSize = mTypedArray.getDimension(R.styleable.RoundProgressBar_textSize, 15);roundWidth = mTypedArray.getDimension(R.styleable.RoundProgressBar_roundWidth, 5);max = mTypedArray.getInteger(R.styleable.RoundProgressBar_max, 100);textIsDisplayable = mTypedArray.getBoolean(R.styleable.RoundProgressBar_textIsDisplayable, true);style = mTypedArray.getInt(R.styleable.RoundProgressBar_style, 0);mTypedArray.recycle();}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);/*** 畫最外層的大圓環*/int centre = getWidth()/2; //獲取圓心的x坐標int radius = (int) (centre - roundWidth/2); //圓環的半徑paint.setColor(roundColor); //設置圓環的顏色paint.setStyle(Paint.Style.STROKE); //設置空心paint.setStrokeWidth(roundWidth); //設置圓環的寬度paint.setAntiAlias(true); //消除鋸齒 canvas.drawCircle(centre, centre, radius, paint); //畫出圓環Log.e("log", centre + "");/*** 畫進度百分比*/paint.setStrokeWidth(0); paint.setColor(textColor);paint.setTextSize(textSize);paint.setTypeface(Typeface.DEFAULT_BOLD); //設置字體int percent = (int)(((float)progress / (float)max) * 100); //中間的進度百分比,先轉換成float在進行除法運算,不然都為0float textWidth = paint.measureText(percent + "%"); //測量字體寬度,我們需要根據字體的寬度設置在圓環中間if(textIsDisplayable && percent != 0 && style == STROKE){canvas.drawText(percent + "%", centre - textWidth / 2, centre + textSize/2, paint); //畫出進度百分比}/*** 畫圓弧 ,畫圓環的進度*///設置進度是實心還是空心paint.setStrokeWidth(roundWidth); //設置圓環的寬度paint.setColor(roundProgressColor); //設置進度的顏色RectF oval = new RectF(centre - radius, centre - radius, centre+ radius, centre + radius); //用於定義的圓弧的形狀和大小的界限switch (style) {case STROKE:{paint.setStyle(Paint.Style.STROKE);canvas.drawArc(oval, 0, 360 * progress / max, false, paint); //根據進度畫圓弧break;}case FILL:{paint.setStyle(Paint.Style.FILL_AND_STROKE);if(progress !=0)canvas.drawArc(oval, 0, 360 * progress / max, true, paint); //根據進度畫圓弧break;}}}public synchronized int getMax() {return max;}/*** 設置進度的最大值* @param max*/public synchronized void setMax(int max) {if(max max){progress = max;}if(progress <= max){this.progress = progress;postInvalidate();}}public int getCricleColor() {return roundColor;}public void setCricleColor(int cricleColor) {this.roundColor = cricleColor;}public int getCricleProgressColor() {return roundProgressColor;}public void setCricleProgressColor(int cricleProgressColor) {this.roundProgressColor = cricleProgressColor;}public int getTextColor() {return textColor;}public void setTextColor(int textColor) {this.textColor = textColor;}public float getTextSize() {return textSize;}public void setTextSize(float textSize) {this.textSize = textSize;}public float getRoundWidth() {return roundWidth;}public void setRoundWidth(float roundWidth) {this.roundWidth = roundWidth;}}package com.example.roundprogressbar;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import com.example.circlepregress.R;public class MainActivity extends Activity {private RoundProgressBar mRoundProgressBar1, mRoundProgressBar2 ,mRoundProgressBar3, mRoundProgressBar4, mRoundProgressBar5;private int progress = 0;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_cricle_progress);mRoundProgressBar1 = (RoundProgressBar) findViewById(R.id.roundProgressBar1);mRoundProgressBar2 = (RoundProgressBar) findViewById(R.id.roundProgressBar2);mRoundProgressBar3 = (RoundProgressBar) findViewById(R.id.roundProgressBar3);mRoundProgressBar4 = (RoundProgressBar) findViewById(R.id.roundProgressBar4);mRoundProgressBar5 = (RoundProgressBar) findViewById(R.id.roundProgressBar5);((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {new Thread(new Runnable() {@Overridepublic void run() {while(progress <= 100){progress += 3;System.out.println(progress);mRoundProgressBar1.setProgress(progress);mRoundProgressBar2.setProgress(progress);mRoundProgressBar3.setProgress(progress);mRoundProgressBar4.setProgress(progress);mRoundProgressBar5.setProgress(progress);try {Thread.sleep(100);} catch (InterruptedException e) {e.printStackTrace();}}}}).start();}});}}activity_cricle_progress.xml剛好做過,通過復寫oncanvas實現的求教 android半圓弧形的進度條問題

C. android 用linearLayout來實現的簽到進度條問題

這個其實很簡單吧,你在application

里就可以計算這個長度了,因為一旦運行程序,不考慮橫豎屏切換,只考慮堅屏的話。屏幕寬高是不會變的。

java">DisplayMetricsmetric=getResources().getDisplayMetrics();
ImageUtils.SCREEN_WIDTH=metric.widthPixels<metric.heightPixels?metric.widthPixels:metric.heightPixels;

這個就是你屏幕的寬高。減去屏幕左右的10dp就是你要的進度條寬度。

publicstaticintdp2Px(Contextc,floatdp)
{
if(c==null)
{
return0;
}
floatdensity=c.getResources().getDisplayMetrics().density;
return(int)(dp*density+0.5f);
}

ImageUtils.PROGRESS_WIDTH=ImageUtils.SCREEN_WIDTH-dp2Px(context,20);

這樣你就不用在adapter裡面進行多次運算了

D. 最新更新的安卓掌閱ireader竟然變成頁碼顯示進度了,以前是百分比顯示進度的,不習慣,能調回去嗎

剛剛從掌閱的官網下載了2.7版,顯示還是百分比的。

建議從官網下載最新版,然後用APP自身的「檢查更新」功能升級,不要相信什麼應用商店軟體管家之類的升級提示,那些多半是加了料的版本。


E. android進度條怎麼顯示百分比

顯示百分比需要自己計算載入的內容,以下以webview示例,webview載入網頁的時候可以增加進度條:
1.從webview中獲取設置
websettings
sws
=
webview.getsettings();
sws.setsupportzoom(true);
sws.setbuiltinzoomcontrols(true);
webview.setinitialscale(25);
webview.getsettings().setusewideviewport(true);
2.注冊setwebchromeclient事件
webview.setwebchromeclient(new
webchromeclient()
{
public
void
onprogresschanged(webview
view,
int
progress)
{
//
activity和webview根據載入程度決定進度條的進度大小
//
當載入到100%的時候
進度條自動消失
//webviewprogressactivity.this.settitle("loading...");
//webviewprogressactivity.this.setprogress(progress
*
100);
if
(progress
==
100)
{
progressbar.setvisibility(view.gone);
//webviewprogressactivity.this.settitle("完成");
}
}
});
3.注意在onprogresschanged中處理進度,progress就是進度值。

F. android怎麼計算每秒鍾的上傳和下載速度

計算的下載速度,舉例說明一下吧。
例如每隔N秒就改變當前下載速度數字的,N秒前的下載進度百分比m%,
N秒後的下載進度百分比n%,當前下載問題的總大小Size【換算成多少kb】
(m%-n%)*Size/N就是
這段時間的下載或上傳速度了。
注意:記得增加判斷一些邊界問題。

G. android的Progressbar怎麼用

在android中,Progressbar可以用來提醒用戶某個任務的進度。下面我們來模擬一個下載進度來看一下。
首先我們創建一個按鈕來啟動一個帶有progressbar的提醒。

編寫代碼為按鈕添加一個點擊事件。

運行效果。

修改progressbar的風格。

完整的代碼。
public void onClick(View v) {

// prepare for a progress bar dialog
progressBar = new ProgressDialog(v.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("File downloading ...");
progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();

//reset progress bar status
progressBarStatus = 0;

//reset filesize
fileSize = 0;

new Thread(new Runnable() {
public void run() {
while (progressBarStatus < 100) {

// process some tasks
progressBarStatus = doSomeTasks();

// your computer is too fast, sleep 1 second
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}

// Update the progress bar
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressBarStatus);
}
});
}

// ok, file is downloaded,
if (progressBarStatus >= 100) {

// sleep 2 seconds, so that you can see the 100%
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

// close the progress bar dialog
progressBar.dismiss();
}
}
}).start();

}

});

}

// file download simulator... a really simple
public int doSomeTasks() {

while (fileSize <= 1000000) {

fileSize++;

if (fileSize == 100000) {
return 10;
} else if (fileSize == 200000) {
return 20;
} else if (fileSize == 300000) {
return 30;
}
// ...add your own

}

return 100;

}

H. android中 progressbar如何顯示百分比,是調用什麼方法嗎

應該多看看開發文檔。貌似是根據值的大小。默認100,如果小的話,就一直有進度。

I. 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"

J. Android中ProgressBar百分比怎麼設置小數

SeekBar是progressbar的子類,最小值默認就是0,表示的意義就是進度完成的百分比,如果你要是表示負數值的話可以做一個轉化就行了,比如你可以設置seekbar的取值【0~200】,然後用getValue()減去100就可以表示【-100~100】

熱點內容
江蘇北斗授時伺服器ip雲空間 發布:2024-04-20 08:53:50 瀏覽:931
dedecms批量上傳圖片 發布:2024-04-20 08:42:11 瀏覽:966
酷q如何編譯 發布:2024-04-20 08:41:27 瀏覽:79
安卓手機數字人民幣怎麼下載 發布:2024-04-20 08:38:21 瀏覽:114
access如何配置資料庫 發布:2024-04-20 08:37:35 瀏覽:504
手寫輸入演算法 發布:2024-04-20 08:29:31 瀏覽:258
朝夕源碼 發布:2024-04-20 08:24:15 瀏覽:276
minilinux 發布:2024-04-20 08:23:38 瀏覽:50
大學php開發培訓 發布:2024-04-20 08:04:35 瀏覽:988
小米2s存儲設置 發布:2024-04-20 07:58:38 瀏覽:901