android中的ProgressBar(进度条)
来源:互联网 发布:重庆干部网络培训 编辑:程序博客网 时间:2024/06/01 07:29
关于进度条的程序:
在activity_main.xml文件中(环境为android4.2.2。在低版本的android好像为main.xml):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<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>
在xml文件中定义了两个进度条(ProgressBar)第一个进度条是直线的存在第一进度和第二进度(在java文件中有定义)。第二个为android默认是进度条,只是一个圆形的进度条在转,不能显示进度。style="?android:attr/progressBarStyleHorizontal"在第一个进度条中表示进度条为横向的。android:visibility="gone"为设置进度条为不可见。
在MainActivity.java中:
package com.yx.progressbar;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends Activity {
//声明变量
private ProgressBar firstBar;
private ProgressBar secondBar;
private Button myButton;
private int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//根据控件的ID取得控件的对象
firstBar = (ProgressBar) findViewById(R.id.firstBar);
firstBar.setMax(200);
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){
//设置进度条为可见状态
firstBar.setVisibility(v.VISIBLE);
secondBar.setVisibility(v.VISIBLE);
}
else if(i<firstBar.getMax()){
firstBar.setProgress(i);//设置主进度条的当前值
firstBar.setSecondaryProgress(i+10);//设置第二进度条的当前值
//默认的进度条无法显示进行的状态
//secondBar.setProgress(i);
}else{
//设置进度条为不可见状态
firstBar.setVisibility(v.GONE);
secondBar.setVisibility(v.GONE);
i=0;
}
i+=10;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
程序为单机一次begin第一个进度条会增加一点。
- android中的ProgressBar(进度条)
- C#中的进度条ProgressBar
- Android UI之ProgressBar(进度条)
- Android自定义进度条(ProgressBar)的问题
- Android初试--更新进度条(ProgressBar)2
- Android UI之ProgressBar(进度条)
- Android常用控件之进度条(Progressbar)
- android Handler控制进度条(ProgressBar)实例
- Android UI之ProgressBar(进度条)
- Android基础-----进度条(ProgressBar手动实现)
- Android高级组件之进度条 (progressBar)
- android 自定义 View(4)- 进度条(ProgressBar)
- Android ProgressBar 进度条
- Android ProgressBar 进度条
- android 进度条(ProgressBar)
- android 进度条(ProgressBar) [
- android------进度条ProgressBar
- android 控件 进度条(ProgressBar)
- SVN服务器搭建与客户端选择
- 6_2程序填空
- 双系统 删除ubuntu,修复win 7引导解决方法
- poj2761——Feed the dogs(划分树或SBT)
- 关于“该文件已在源编辑器之外修改。是否重新加载它”问题
- android中的ProgressBar(进度条)
- 第六周上级任务2
- 新的开始
- Java初学者入门应该掌握的30个概念
- Pig实战
- Pig Latin ── Language for Large Data Processing
- iOS网络编程实践--蓝牙对等网络通信实例讲解
- 在windows7系统中删除Linux grub启动项方法
- Flex 输出日志