发布于 2016-02-18 21:44:27 | 197 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


本篇文章是对android中ProgressDialog与ProgressBar的使用进行了详细的分析介绍,需要的朋友参考下

一 、ProgressDialog
ProgressDialog与ProgressBar在UI中动态显示一个加载图标显示程序运行状态。
ProgressDialog是继承自Android.app.ProgressDialog所设计的互动对话窗口,使用时,必须新建ProgressDialog对象,在运行时会弹出“对话框”作为提醒,此时应用程序后台失去焦点(即此时无法对UI组件进行操作),直到进程结束后,才会将控制权交给应用程序,如果在Activity当中不希望后台失焦,又希望提示User有某后台程序正处于忙碌阶段,那么ProgressBar就会派上用场了。


ProgressDialog mProgressDialog = new ProgressDialog(TestProgerssDialogActivity.this);
// 设置mProgressDialog风格
mProgressDialog.setProgress(ProgressDialog.STYLE_SPINNER);//圆形
mProgressDialog.setProgress(ProgressDialog.STYLE_HORIZONTAL);//水平
// 设置mProgressDialog标题
mProgressDialog.setTitle("提示");
// 设置mProgressDialog提示
mProgressDialog.setMessage("这是一个圆形进度条对话框");
// 设置mProgressDialog进度条的图标
mProgressDialog.setIcon(R.drawable.flag); 
// 设置mProgressDialog的进度条是否不明确
//不滚动时,当前值在最小和最大值之间移动,一般在进行一些无法确定操作时间的任务时作为提示,明确时就是根据你的进度可以设置现在的进度值
mProgressDialog.setIndeterminate(false);
//mProgressDialog.setProgress(m_count++);
// 是否可以按回退键取消
mProgressDialog.setCancelable(true);
// 设置mProgressDialog的一个Button
mProgressDialog.setButton("确定", new DialogInterface.OnClickListener()
{ 
  @Override 
  public void onClick(DialogInterface dialog, int which) 
  { 
    dialog.cancel(); 
   } 
});
// 显示mProgressDialogmProgressDialog.show();


 mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

   @Override
   public void onCancel(DialogInterface dialog) {
    // TODO Auto-generated method stub
    mProgressDialog.hide();
    webview.stopLoading();

   }
  });

当有ProgressDialog时,点击back时,会首先取消ProgressDialog ,以上代码可以监听进度条被取消事件(也就是点击Back键取消ProgressDialog),此时可以在这里作一些取消后台操作的处理。

二、ProgressBar
XML重要属性
android:progressBarStyle:默认进度条样式
android:progressBarStyleHorizontal:水平样式

重要方法
getMax():返回这个进度条的范围的上限
getProgress():返回进度
getSecondaryProgress():返回次要进度
incrementProgressBy(int diff):指定增加的进度
isIndeterminate():指示进度条是否在不确定模式下
setIndeterminate(boolean indeterminate):设置不确定模式下
setVisibility(int v):设置该进度条是否可视

重要事件
onSizeChanged(int w, int h, int oldw, int oldh):当进度值改变时引发此事件


<?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
     android:orientation="vertical"
     android:layout_width="fill_parent"  
     android:layout_height="fill_parent">  

     <TextView
android:layout_width="fill_parent"  
android:layout_height="wrap_content"
android:text="Welcome to blog" />  
     <ProgressBar
android:id="@+id/rectangleProgressBar"  
style="?android:attr/progressBarStyleHorizontal" mce_style="?android:attr/progressBarStyleHorizontal"   
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
     <ProgressBar
android:id="@+id/circleProgressBar"  
style="?android:attr/progressBarStyleLarge" mce_style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>

     <Button android:id="@+id/button"
    android:text="Show ProgressBar"  
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
 </LinearLayout> 



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务