ProgressBar学习
来源:互联网 发布:现货白银指标公式源码 编辑:程序博客网 时间:2024/06/05 02:05
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <SeekBar android:id="@+id/progressBar1" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" android:progress="20" android:secondaryProgress="40" /> <Button android:id="@+id/add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/add"/> <Button android:id="@+id/reduce" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/reduce"/> <Button android:id="@+id/reset" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/reset"/> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:id="@+id/show" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/show"/></LinearLayout>
MainActivity.java
package com.example.progressbardemo;import android.os.Bundle;import android.app.Activity;import android.app.ProgressDialog;import android.content.DialogInterface;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ProgressBar;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends Activity implements OnClickListener{private ProgressBar pb;private Button add;private Button reduce;private Button reset;private TextView text;private Button show;private ProgressDialog pd;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);pb = (ProgressBar) findViewById(R.id.progressBar1);add = (Button) findViewById(R.id.add);reduce = (Button) findViewById(R.id.reduce);reset = (Button) findViewById(R.id.reset);text = (TextView) findViewById(R.id.text); show = (Button) findViewById(R.id.show);int firstPb = pb.getProgress(); int secondPb = pb.getSecondaryProgress();int maxPb = pb.getMax();text.setText("第一进度百分比:"+(int)(firstPb/(float)maxPb*100)+"%;第二进度百分比:"+(int)(secondPb/(float)maxPb*100)+"%");add.setOnClickListener(this);reduce.setOnClickListener(this);reset.setOnClickListener(this);show.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.add://第一进度和第二进度各增加10pb.incrementProgressBy(10);pb.incrementSecondaryProgressBy(10);break;case R.id.reduce://第一进度和第二进度各减少10pb.incrementProgressBy(-10);pb.incrementSecondaryProgressBy(-10);break;case R.id.reset:pb.setProgress(20);pb.setSecondaryProgress(40);break;case R.id.show:/** * 页面显示风格 *///新建ProgressDialog对象pd = new ProgressDialog(MainActivity.this);//设置显示风格pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);//设置标题pd.setTitle("胖子");//设置对话框里的文字信息pd.setMessage("奔跑吧,胖子!!!");//设置图标pd.setIcon(R.drawable.ic_launcher);/** * 设定关于ProgressBar的一些属性 *///设定最大进度pd.setMax(100);//设定初始化已经增长到的进度pd.incrementProgressBy(20);//进度条是明确显示进度的pd.setIndeterminate(false);/** * 设定一个确定按钮 */pd.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubToast.makeText(MainActivity.this, "奔跑吧,胖子!!!", Toast.LENGTH_SHORT).show();}});//是否可以通过返回按钮退出对话框pd.setCancelable(true);//显示ProgressDialogpd.show();break;default:break;}}}
0 0
- ProgressBar学习
- Ext.ProgressBar学习
- ExtJS学习------Ext.ProgressBar
- android学习----ProgressBar 进度条
- 学习笔记 progressbar
- 学习篇---progressbar
- 【Android学习】进度条ProgressBar
- Android学习 ProgressBar(进度条)
- Android学习-ProgressBar进度条
- Android ProgressBar学习与掌握。
- Android 高级控件学习--ProgressBar
- Android学习路之ProgressBar
- Seekbar&ProgressBar组件的学习
- ProgressBar及其子类系列学习
- 学习笔记-简单自定义ProgressBar
- ProgressBar
- progressbar
- ProgressBar
- 带参数的函数main()
- Android Fragment全攻略
- Python:Windows7 (64位)系统下安装Scrapy详细教程
- linux基础(十五)----linux编程基础----linux条件控制语句----case语句
- 相机标定(实践)
- ProgressBar学习
- JVM垃圾收集器异同
- Android Training - 高效地显示Bitmap(两种缓存Bitmap的方式)与优化Bitmap的内存使用
- cdev
- 10个ADC滤波算法
- LeetCode 292 Nim Game
- BASEDAO 参考
- MySQL 用localhost不能连上mysql,但用127.0.0.1却可以,是什么原因?
- ListView下拉刷新