android简单进度条
来源:互联网 发布:青岛seo做的好的网站 编辑:程序博客网 时间:2024/05/21 06:42
效果:
一:布局文件
activity_main.xml文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <!-- 大环形进度条 --> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="一:大环形进度条" android:textSize="25sp" /> <ProgressBar style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:progressDrawable="@drawable/myprogressbarstyle" /> <!-- 小环形进度条 --> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="一:小环形进度条" android:textSize="25sp" /> <ProgressBar style="?android:attr/progressBarStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <!-- 水平进度条 --> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="一:水平进度条" android:textSize="25sp" /> <!-- indeterminate是否不精确显示 --> <!-- max进度条总的范围 --> <!-- progress第一进度 --> <!-- secondaryProgress第二进度 --> <!-- progressDrawable进度条样式 --> <ProgressBar android:id="@+id/myprogressbar" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="3dp" android:layout_marginRight="3dp" android:indeterminate="false" android:max="100" android:progress="40" android:progressDrawable="@drawable/myprogressbarstyle" android:secondaryProgress="60" /> <Button android:id="@+id/btn_progressbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="进度条前进" /> <Button android:id="@+id/btn_progressbardialog" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="对话框式进度条" /></LinearLayout>注意: android:progressDrawable="@drawable/myprogressbarstyle"须:
myprogressbarstyle.xml文件:(可以自行修改)
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- centerColor背景色 --> <!-- startColor顶部线条颜色 --> <!-- endColor底部线条颜色 --> <item android:id="@android:id/background"> <shape> <corners android:radius="5dip" /> <gradient android:angle="270" android:centerColor="#bfbfbf" android:centerY="0.75" android:endColor="#bfbfbf" android:startColor="#bfbfbf" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <corners android:radius="5dip" /> <gradient android:angle="270" android:centerColor="#00ffff" android:centerY="0.75" android:endColor="#00ffff" android:startColor="#00ffff" /> </shape> </clip> </item> <item android:id="@android:id/progress"> <clip> <shape> <corners android:radius="5dip" /> <gradient android:angle="270" android:centerColor="#0000ff" android:centerY="0.75" android:endColor="#0000ff" android:startColor="#0000ff" /> </shape> </clip> </item></layer-list>
二:src
MainActivity.java文件:
package com.peng.butongprograssbar;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.view.Window;import android.widget.Button;import android.widget.ProgressBar;import android.widget.Toast;import android.app.Activity;import android.app.ProgressDialog;import android.content.DialogInterface;public class MainActivity extends Activity implements OnClickListener {// 声明控件private Button btn_progressbar;private Button btn_progressbardialog;private ProgressBar myprogressbar;private ProgressDialog showDialog;// 数据int firstprogress;// 第一进度int secondprogress;// 第二进度@Overrideprotected 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(10000);//注意:这里默认水平进度条的最大值为10000,设置为10000出现后马上消失setProgress(9999);// 获取控件initViews();// 初始化数据initDatas();// 为控件添加事件setViewsListener();}private void initDatas() {firstprogress = myprogressbar.getProgress();// 第一进度secondprogress = myprogressbar.getSecondaryProgress();// 第二进度}private void setViewsListener() {btn_progressbar.setOnClickListener(this);btn_progressbardialog.setOnClickListener(this);}private void initViews() {btn_progressbar = (Button) findViewById(R.id.btn_progressbar);btn_progressbardialog = (Button) findViewById(R.id.btn_progressbardialog);myprogressbar = (ProgressBar) findViewById(R.id.myprogressbar);}// 监听事件--处理@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.btn_progressbar: {if (100 != secondprogress) {myprogressbar.setProgress(firstprogress++);myprogressbar.setSecondaryProgress(secondprogress++);} else {if (100 != firstprogress) {myprogressbar.setProgress(firstprogress++);} else {Toast.makeText(MainActivity.this, "全部加载完成1", 0).show();}}break;}case R.id.btn_progressbardialog: {showDialog = new ProgressDialog(MainActivity.this);showDialog.setTitle("提示");showDialog.setIcon(R.drawable.ic_launcher);showDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);showDialog.setMessage("正在加载中...");showDialog.setMax(100);showDialog.incrementProgressBy(20);showDialog.setIndeterminate(false);showDialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {Toast.makeText(MainActivity.this, "exit!",Toast.LENGTH_SHORT).show();}});showDialog.setCancelable(true);// 物理返回按键退出对话框showDialog.show();break;}}}}
1 0
- android简单进度条
- Android进度条简单练习实例
- android竖向进度条简单实现
- android 简单的缓冲进度条
- android 简单自定义环形进度条
- Android一个简单易用的进度条
- Android的最简单的进度条
- android 圆形进度条的简单实现
- Android简单自定义进度条(小白进)
- 简单进度条
- Android之Handler简单运用(控制进度条)
- Android透明无边框圆形进度条之最简单实现
- Android透明无边框圆形进度条之最简单实现
- Android透明无边框圆形进度条之最简单实现
- Android UI控件之ProgressBar进度条简单实现
- Android之一个简单的进度条工具类
- Android透明无边框圆形进度条之最简单实现
- android自定义View之(二)------简单进度条显示样例篇
- 学习笔记——Maven实战(十)Maven 3,是时候升级了
- mybatis中#和$的区别
- HTML文档分节
- uva11400Lighting System Design(简单DP+贪心)
- 呵呵
- android简单进度条
- MaxCompute 学习计划(二)
- 三国佚事——巴蜀之危
- Linux内核开发之内存与I/O访问(六)
- mysql字符集
- 数据结构:静态查找表
- getOutputStream() has already been called for this response
- 勾股定理
- 正则表达式