ProgressBar进度条的实现
来源:互联网 发布:unity3d 指南针源码 编辑:程序博客网 时间:2024/06/11 19:35
各式各样的进度条,这里不演示效果了,大家可以自己写写,动手操作操作,看看效果
MainActivty代码:
package com.example.sixth_progressbar_android;import android.app.Activity;import android.app.ProgressDialog;import android.content.DialogInterface;import android.os.Bundle;import android.view.View;import android.view.Window;import android.widget.Button;import android.widget.ProgressBar;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends Activity implements View.OnClickListener{ private ProgressBar press; private Button add; private Button reduce; private Button reset; private Button show; private ProgressDialog progressdialog; private TextView text2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //启用窗口特征,显示带进度和不带进度的进度条 requestWindowFeature(Window.FEATURE_PROGRESS); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_main); //带进度进度条 与 不带进度进度条 setProgressBarVisibility(true); setProgressBarIndeterminateVisibility(true); setProgress(5000); intt(); } private void intt() { press = (ProgressBar)findViewById(R.id.horiz); add = (Button) findViewById(R.id.add); reduce = (Button)findViewById(R.id.reduce); reset = (Button) findViewById(R.id.reset); text2 = (TextView)findViewById(R.id.text1); show = (Button)findViewById(R.id.show); //获取第一进度 int first = press.getProgress(); //获得第二进度 int second = press.getSecondaryProgress(); //获取最大进度 int max = press.getMax(); text2.setText("第一进度:"+(int)(first/(float)max*100) +"% 第二进度:"+(int)(second/(float)max*100) +"%"); //设置监听器 add.setOnClickListener(this); reset.setOnClickListener(this); reduce.setOnClickListener(this); show.setOnClickListener(this); } @Override public void onClick(View view) { switch(view.getId()) { case R.id.add: { //增加第一进度和第二进度10% press.incrementProgressBy(10); press.incrementSecondaryProgressBy(10); break; } case R.id.reduce: { //减少第一进度和第二进度10% press.incrementProgressBy(-20); press.incrementSecondaryProgressBy(-20); break; } case R.id.reset: { //重置 press.setProgress(50); press.setSecondaryProgress(80); break; } case R.id.show : { /* *页面显示设置 */ //页面设置,,新建一个ProgressDialog progressdialog = new ProgressDialog(MainActivity.this); //设置显示风格 progressdialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); //设置标题 progressdialog.setTitle("模拟器"); //设置文本框内容 progressdialog.setMessage("欢迎进入"); //设置图标 progressdialog.setIcon(R.mipmap.ic_launcher); /* *关于progressdialog一些属性设置 */ //设定最大进度 progressdialog.setMax(100); //初始化进度 progressdialog.incrementProgressBy(50); //进度条是明确清晰可见 progressdialog.setIndeterminate(false); /* *设置一个确定按钮 */ progressdialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Toast.makeText(MainActivity.this,"退出窗口",Toast.LENGTH_SHORT).show(); } }); //是否可以通过返回按钮退出对话框 progressdialog.setCancelable(true); //显示progressdialog progressdialog.show(); break; } } text2.setText("第一进度:"+(int)(press.getProgress()/(float)press.getMax()*100)+"% " + " 第二进度:"+(int)(press.getSecondaryProgress()/(float)press.getMax()*100)+"%"); }}xml文件代码:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout 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" tools:context="com.example.sixth_progressbar_android.MainActivity"> <ProgressBar style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/progressBar" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/progressBar2" android:layout_below="@+id/progressBar" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="35dp" /> <ProgressBar style="?android:attr/progressBarStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/progressBar3" android:layout_below="@+id/progressBar2" android:layout_marginTop="35dp" /> <ProgressBar android:progress="80" android:secondaryProgress="50" android:max="100" style="@android:style/Widget.Holo.Light.ProgressBar.Horizontal" android:progressDrawable="@drawable/progress_horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/horiz" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/add" android:text="增加" android:layout_below="@+id/horiz" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/reduce" android:text="减少" android:layout_below="@+id/add" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/reset" android:text="重置" android:layout_below="@+id/reduce" /> <TextView android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="50dp" android:layout_below="@+id/reset" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="显示对话框进度条" android:id="@+id/show" android:layout_below="@+id/text1"/></RelativeLayout>
0 0
- ProgressBar进度条的实现
- 自定义进度条ProgressBar的实现
- 安卓进度条(ProgressBar)的实现
- 圆形进度条ProgressBar 的实现方式
- 实现动态更新ProgressBar的水平进度条
- 使用progressbar实现进度条。
- 使用ProgressBar实现进度条
- android:progressbar实现进度条
- 使用ProgressBar实现进度条
- 使用ProgressBar实现进度条
- progressbar 进度条的使用
- backgroundworker使用 实现进度条ProgressBar
- ProgressBar组件实现实时进度条
- backgroundworker使用 实现进度条ProgressBar
- 使用ProgressBar实现加载进度条
- android ProgressBar 实现自定义进度条
- 使用ProgressBar实现加载进度条
- 自定义ProgressBar实现圆弧进度条
- kafka2.9.2的分布式集群安装和demo(java api)测试
- Thinking In UML 的读书笔记(一)需求分析之前的准备工作
- JAVA之树(创建,遍历,修改,删除,标签,提示信息,展开折叠事件...)
- [HihoCoder]#1048 : 状态压缩·二
- java面向对象的特征
- ProgressBar进度条的实现
- 【设计模式】## 2、模板模式##
- 数据结构算法题
- java中volatile关键字的含义
- IDL环境下,HDF文件转TIFF格式
- RPC thrift学习笔记
- Codeforces 78C Beaver Game(数论、博弈)
- C++给定范围进行按位与运算
- 友言