Android ProgressBar实现加载进度条

progressBar Android进度条组件。

progressBar的关键属性:

android:max="100"     最大显示进度条

android:progress="500"     第一显示进度

android:secondaryProgress="80"     第二显示进度

android:indeterminate="true"     设置是否精确显示

progressBar的关键方法:

setProgress(int)     设置第一进度。

setSecondaryProgress(int)     设置第二进度

getProgress()     获取第一进度

getSecondaryProgress()     获取第二进度

incrementProgressBy(int)     增加或减少第一进度

incrementSecondaryProgressBy(int)      增加或减少第二进度

getMax()    获取最大进度。

progressBar显示风格:

不设置style为中环形进度条

style="?android:attr/progressBarStyleLarge"     //大环进度条

style= "?android:attr/progressBarStyleSmall"     //小环形进度条

style= "?android:attr/progressBarStyleHorizontal"     //水平进度条

 

progressBar分类

          精确显示进度和不可精确显示进度。

 

标题栏上的progressBar

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout. activity_main);

//启动窗口特征

requestWindowFeature(Window. FEATURE_PROGRESS);

requestWindowFeature(Window. FEATURE_INDETERMINATE_PROGRESS);

//显示两种进度条。

setProgressBarVisibility( true);

setProgressBarIndeterminateVisibility( true);

setProgress(600);     //设置带进度的进度条的刻度  最大进度值为常量10000

}

对话框形式的进度条

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout. activity_main);

//新建progressDialog对象

progressDialog=new ProgressDialog(MainActivity.this);

//设置显示风格

progressDialog.setProgressStyle(progressDialog .STYLE_HORIZONTAL);

//设置标题

progressDialog.setTitle("" );

/*

* 设定关于捧欧冠热身赛Bar的一些属性

*/

//设定最大进度

progressDialog.setMax(100);

//设定初始化已经增长的进度

progressDialog.incrementProgressBy(50);

//指定进度条是明确显示进度的

progressDialog.setIndeterminate(false);

//设定一个按钮

progressDialog.setButton(DialogInterface.BUTTON_POSITIVE,"确定 ", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

Toast. makeText(MainActivity.this, "", Toast.LENGTH_LONG).show();

}

});

//是否可以通过返回按钮退出对话框

progressDialog.setCancelable(true);

//显示progreDialog

progressDialog.show();

}

时间: 2024-08-25 01:19:41

Android ProgressBar实现加载进度条的相关文章

【android】带加载进度条的WebView (附demo下载)

/** * * 此WebViewWithProgress继承自Relativielayout, * 如果要设置webview的属性,要先调用getWebView()来取得 * webview的实例 * * @author Administrator * */ public class WebViewWithProgress extends RelativeLayout{ private Context context; private WebView mWebView = null; //水平进

Android开发--------------WebView(二)之WebView的滑动底部顶部监听,加载进度条等设置

整理一下WebView的一些常用设置,滑动监听,让跳转的页面也在WebView里显示,加载进度,获得标题等等 一,滑动监听 滑动监听的话是需要在WebView基础之上在加强一下,因为在WebView没有直接监听滑动的方法,看WebView的源码则会发现有一个 protected void onScrollChanged(int l, int t, int oldl, int oldt) : 这个方法.是受到保护的所以我们无法直接使用,所以我们写一个加强的WebView,利用接口回调. Scrol

给WebView添加漂亮的加载进度条

为了增强用户体验,所有在WebView头部给加了个进度条,看起来不错哦. 布局XMl:activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent&q

缓冲进度条或加载进度条

缓冲进度条或加载进度条,在加载页面或者视频加载过程中,为了做到更好的UI及App功能体验交互,这些缓冲加载的等待效果是必不可少的: 下面来看一下旋转的动画效果:那么,他们的具体源码在这里:loading_1: <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" andro

webView 加载进度条,webView返回键重写机制

1.图片延时加载 brower = (WebView) this.findViewById(R.id.brower); settings = brower.getSettings(); settings.setJavaScriptEnabled(true); //阻塞图片下载 settings.setBlockNetworkImage(true); private class Client extends WebViewClient     {         @Override        

自定义View基础之——图片加载进度条

学会了Paint,Canvas的基本用法之后,我们就可以动手开始实践了,先写个简单的图片加载进度条看看. 按照惯例,先看效果图,再决定要不要往下看: 既然看到这里了,应该是想了解这个图片加载进度条了,我们先看具体用法,再看自定义View的实现: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.co

Unity3D 场景切换加载进度条实现

需要三个场景,场景A,场景B,场景C: 场景A:一个按钮,点击加载场景B: 场景B:从A切换到C过度场景,加载进度条: 场景C:目标场景: 创建OnProgress.cs脚本: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class OnProgress : MonoBehaviour { publi

网页加载进度条的实现

本次主要介绍一下网页加载进度的实现.如下图,在页面加载的时候,上方红色的进度条 网页加载进度的好处是能够更好的反应当前网页的加载进度情况,loading进度条可用动画的形式从开始0%到100%完成网页加载这一过程.但是目前的浏览器并没有提供页面加载进度方面的接口,也就是说页面还无法准确返回页面实际加载的进度,本文中我们使用jQuery来实现页面加载进度条效果. 首先我们要知道的是,目前没有任何浏览器可以直接获取正在加载对象的大小.所以我们无法通过数据大小来实现0-100%的加载显示过程. 因此我

网站顶部显示预加载进度条preload.js

网站加载的速度快的话,不会显示进度条加载时候的样式. 支持性主流浏览器都支持,ie浏览器需要9以上9也支持. 使用方法 <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script src="js/preload.js"></script> <script type="text/javascript">