关于ProgressBar的示例一请见这里
http://byandby.iteye.com/blog/816494
这也是一个小例子比较简单 下边是官方文档对xml文件属性的一些简单描述
Attribute Description
android:indeterminate Allows to enable the indeterminate mode.
android:indeterminateBehavior Defines how the indeterminate mode should behave when the progress reaches max.
android:indeterminateDrawable Drawable used for the indeterminate mode.
android:indeterminateDuration Duration of the indeterminate animation.
android:indeterminateOnly Restricts to ONLY indeterminate mode (state-keeping progress mode will not work).
android:interpolator
android:max Defines the maximum value the progress can take.
android:maxHeight An optional argument to supply a maximum height for this view.
android:maxWidth An optional argument to supply a maximum width for this view.
android:minHeight
android:minWidth
android:progress Defines the default progress value, between 0 and max.
android:progressDrawable Drawable used for the progress mode.
android:secondaryProgress Defines the secondary progress value, between 0 and max.
我们先看一下运行效果吧。
示例布局文件
<?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="@string/hello"
/>
<ProgressBar
android:id="@+id/firstBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<ProgressBar
android:id="@+id/secondBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="begin"/>
</LinearLayout>
Activity 类
package xiaohang.zhimeng;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
public class Activity01 extends Activity {
//声明变量
private ProgressBar firstBar = null;
private ProgressBar secondBar = null;
private Button myButton;
private int i = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//根据控件的ID取得代表控件的对象
firstBar = (ProgressBar)findViewById(R.id.firstBar);
secondBar = (ProgressBar)findViewById(R.id.secondBar);
myButton = (Button)findViewById(R.id.myButton);
myButton.setOnClickListener(new ButtonListener());
}
class ButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
if (i == 0 || i == 10) {
//设置进度条处于可见的状态
firstBar.setVisibility(View.VISIBLE);
firstBar.setMax(150);
secondBar.setVisibility(View.VISIBLE);
}else if ( i< firstBar.getMax() ) {
//设置主进度条的当前值
firstBar.setProgress(i);
//设置第二进度条的当前值
firstBar.setSecondaryProgress(i + 10);
}else {
//设置主进度为0
firstBar.setProgress(0);
//设置第二进度为0
firstBar.setSecondaryProgress(0);
//把i的值 设置为0
i = 0;
firstBar.setVisibility(View.GONE);
secondBar.setVisibility(View.GONE);
}
i = i + 10;
}
}
}
android 2.0 APILEVEL 5
源码见 附件 运行效果图片 见附件
- 大小: 25.9 KB
分享到:
相关推荐
此为Android ProgressBar 简单进度条的实现及示例下载源码,基本思路是:将模拟任务分成大小为100个的数组,任务完成度--默认为0,状态完成度默认也为0,然后构造一个线程用于显示消息,然后定义dowork()函数,完成...
本文实例讲述了Android编程自定义ProgressBar。分享给大家供大家参考,具体如下: <?xml version=1.0 encoding=UTF-8?> <rotate xmlns:android=http://schemas.android.com/apk/res/android android:...
说明 ProgressBar一般用于显示一个过程,... <ProgressBar android:layout_width=wrap_content android:layout_height=wrap_content> //代码中控制显隐藏 mProgressBar = (ProgressBar) findViewById(R.id.progress
Android中ProgressBar、SeekBar、RatingBar、ImageSwitcher实现相册滑动示例代码
主要介绍了Android编程实现自定义ProgressBar样式功能,涉及针对背景色及一级、二级进度条颜色的操作技巧,需要的朋友可以参考下
Android基本控件使用示例,包含以下控件实例: AutoCompleteTextView CheckBox TimePicker DatePicker EditText GridView ImageButton ImageShow ImageView ProgressBar RadioGroup RatingBar SeekBar Spinner Tab
本文实例讲述了Android开发使用ProgressBar实现进度条功能。分享给大家供大家参考,具体如下: 进度条ProgressBar的使用主要有两种方向; 1.使用官方默认样式 2.使用自定义样式 先看效果: 详细代码实现文末给出 ...
Android中通过SeekBar手动控制ProgressBar与模拟下载自动更新进度条示例代码.zip
本文主要介绍android 进度条组件ProgressBar,这里整理进度条的实现代码和效果图,帮助大家学习理解Android 进度条的知识,有兴趣的小伙伴可以参考下
主要介绍了Android开发中自定义ProgressBar控件的方法,结合实例形式分析了自定义ProgressBar控件的定义与使用方法,需要的朋友可以参考下
基于Android 的PorgressBar和ProgressDidlog的简单示例。Android测试版本:4.2
android webView+progressBar刷新加载示例.有需要的可以自行下载查看
主要为大家详细介绍了Android实现进度条(ProgressBar)的功能与用法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
主要为大家详细介绍了Android自定义带动画效果的圆形ProgressBar,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下