android ProgressBar 示例二

关于ProgressBar的示例一请见这里[url]http://byandby.iteye.com/blog/816494[/url]
这也是一个小例子比较简单 下边是官方文档对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.
我们先看一下运行效果吧。

[img]http://dl.iteye.com/upload/attachment/352268/ed1097ff-c3ae-381f-8213-4d236614919a.jpg[/img]

示例布局文件
<?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
源码见 附件 运行效果图片 见附件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值