当前位置:首页 » 安卓系统 » 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】

热点内容
地铁逃生怎么进入游戏安卓 发布:2024-05-03 17:49:35 浏览:992
aws云存储 发布:2024-05-03 17:48:50 浏览:954
安卓微信王者号怎么转成苹果 发布:2024-05-03 17:44:38 浏览:745
原子类源码 发布:2024-05-03 17:44:19 浏览:165
安卓浏览图片如何全屏 发布:2024-05-03 17:24:08 浏览:104
传奇仓库脚本 发布:2024-05-03 17:23:56 浏览:541
2010数据库技术及应用 发布:2024-05-03 17:21:51 浏览:921
小米账号密码忘了怎么 发布:2024-05-03 17:17:44 浏览:780
皇家农场脚本 发布:2024-05-03 16:46:41 浏览:458
顺序存储链式存储 发布:2024-05-03 16:46:41 浏览:879