ProgressBar的使用以及实现进度条的增减
来源:互联网 发布:21端口查看 编辑:程序博客网 时间:2024/03/29 19:39
重要方法提要
设置窗口特征: requestWindowFeature(Window.FEATURE_PROGRESS);
获取进度条:
int first=progressBar.getProgress();
int second=progressBar.getSecondaryProgress();
int max=progressBar.getMax();
改变进度条的大小
progressBar.incrementProgressBy(int);
1. 布局
<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:orientation="vertical"
tools:context="com.example.progressbar.MainActivity" >
<ProgressBar
android:progress="50"
android:secondaryProgress="80"
android:max="100"
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="增加" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="减少" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="重置" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
2.java 代码
package com.example.progressbar;
import android.R.integer;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends Activity implements android.view.View.OnClickListener{
private Button button1;
private Button button2;
private Button button3;
private ProgressBar progressBar;
private TextView textview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置窗口特征
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
setProgressBarIndeterminateVisibility(true);
progressBar=(ProgressBar) findViewById(R.id.progressBar1);
button1=(Button) findViewById(R.id.button1);
button2=(Button) findViewById(R.id.button2);
button3=(Button) findViewById(R.id.button3);
textview=(TextView) findViewById(R.id.textView1);
//获取第一进度,第二进度,最大进度
int first=progressBar.getProgress();
int second=progressBar.getSecondaryProgress();
int max=progressBar.getMax();
//将获取的显示出来
textview.setText("第一进度"+first+" 第二进度"+second+" 第一进度占的百分比"+
(first/(float)max)*100+"%");
//按钮设置监听事件
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
//增加进度条的刻度
case R.id.button1:
progressBar.incrementProgressBy(10);
progressBar.incrementSecondaryProgressBy(10);
break;
//减少进度条的刻度
case R.id.button2:
progressBar.incrementProgressBy(-10);
progressBar.incrementSecondaryProgressBy(-10);
break;
case R.id.button3:
progressBar.setProgress(50);
progressBar.setSecondaryProgress(80);
break;
}
textview.setText("第一进度"+progressBar.getProgress()+" 第二进度"+progressBar.getSecondaryProgress()+" 第一进度占的百分比"
+(progressBar.getProgress()/(float)progressBar.getMax())*100+"%");
}
}
- ProgressBar的使用以及实现进度条的增减
- Android-ProgressBar进度条以及对话框的使用
- ProgressBar进度条的实现
- progressbar 进度条的使用
- 自定义进度条ProgressBar的实现
- Android ProgressBar进度条的使用
- Android ProgressBar进度条的使用
- wpf 进度条 ProgressBar的使用
- Android progressbar 进度条的使用
- 02.进度条progressBar的使用
- 使用progressbar实现进度条。
- 使用ProgressBar实现进度条
- 使用ProgressBar实现进度条
- 使用ProgressBar实现进度条
- 安卓进度条(ProgressBar)的实现
- 圆形进度条ProgressBar 的实现方式
- 实现动态更新ProgressBar的水平进度条
- java swing中ProgressBar(进度条)的使用
- nginx之proxy_pass的session丢失
- python混合笔记(一)
- CF 335 div.2-A/606A Magic Spheres(读错题意系列)
- 知乎上关于Java Bean的比喻
- CUDA入门(10):CUDA 流
- ProgressBar的使用以及实现进度条的增减
- 关于Bean的二三事
- freemarker简单入门Demo
- FLV科普2 FLV相关工具FlvParse
- 电子电路开发基础
- 能被3和11整除吗(数论)
- C/C++学习(五)冒泡排序
- Android资源的定义和引用
- 珍藏的链接