版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】进度条ProgressBar及ProgressDialog的示例分析
废话不多说,直接上代码Main代码
package
cessbardemo;
import
android.app.Dialog;
import
android.app.ProgressDialog;
import
android.content.DialogInterface;
import
android.os.Bundle;
import
android.support.v7.app.AppCompatActivity;
import
android.util.Log;
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
AppCompatActivity
implements
View.OnClickListener{
/*ProgressBar
简介:ProgressBar是进度条组件,通常用于向用户展示某个耗时操作完成的进度,而不让用户感觉是程序失去了响应,从而更好地提升用户界面的友好性
课程目标:
1、制定ProgressBar显示风格(系统默认)
2、ProgressBar的分类
水平进度条,能精确显示,圆圈进度条,不精确显示
3、标题上ProgressBar的设置
4、ProgressBar的关键属性
5、ProgressBar的关键方法
6、ProgressDiglog的基础使用
7、自定义ProgressBar样式*/
private
ProgressBar
progressBar3;
private
Button
show;
private
Button
add;
private
Button
res;
private
Button
reset;
private
TextView
textView;
private
ProgressDialog
progressDialog;
@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(false);
//
最大值为Max=10000;
//setProgress(600);
init();
}
private
void
init()
{
;
progressBar3=
(ProgressBar)
findViewById(R.gressBar3);
show=
(Button)
findViewById(R.id.show);
add=
(Button)
findViewById(R.id.add);
res=
(Button)
findViewById(R.id.res);
reset=
(Button)
findViewById(R.id.reset);
textView=
(TextView)
findViewById(R.id.textView);
int
first=progressBar3.getProgress();/*获取第一进度*/
int
second=progressBar3.getSecondaryProgress();/*获取第二进度*/
int
max=progressBar3.getMax();/*获取最大进度*/
textView.setText("第一进度条百分比"+(int)((first/(float)max)*100)+"%"+"第二进度条百分比"+(int)(second/(float)max*100)+"%");
add.setOnClickListener(this);
res.setOnClickListener(this);
reset.setOnClickListener(this);
show.setOnClickListener(this);
}
@Override
public
void
onClick(View
v)
{
switch
(v.getId()){
case
R.id.add:
progressBar3.incrementProgressBy(10);
progressBar3.incrementSecondaryProgressBy(10);
break;
case
R.id.res:
progressBar3.incrementProgressBy(-10);
progressBar3.incrementSecondaryProgressBy(-10);
break;
case
R.id.reset:
progressBar3.setProgress(50);
progressBar3.setSecondaryProgress(50);
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.setMax(100);
//
设置初始化已经增长的进度
progressDialog.incrementProgressBy(50);
//
设置进度条明确显示进度
progressDialog.setIndeterminate(false);
/*
设定一个确定按钮*/
progressDialog.setButton(DialogInterface.BUTTON_POSITIVE,"确定",
new
Dialog.OnClickListener()
{
@Override
public
void
onClick(DialogInterface
dialog,
int
which)
{
Toast.makeText(MainActivity.this,"欢迎大家支持慕课网",Toast.LENGTH_SHORT).show();
}
});
//
是否可以通过返回按钮来取消对话框
progressDialog.setCancelable(true);
//
显示ProgressDialog
progressDialog.show();
}
textView.setText("第一进度条百分比"+(int)((progressBar3.getProgress()/(float)progressBar3.getMax())*100)+"%"+"第二进度条百分比"+(int)(progressBar3.getSecondaryProgress()/(float)progressBar3.getMax()*100)+"%");
}
}layout中activity_main.xml代码<?xml
version="1.0"
encoding="utf-8"?>
<RelativeLayout
xmlns:android="/apk/res/android"
xmlns:tools="/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"
tools:context="cessbardemo.MainActivity">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="112dp"
/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar2"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="256dp"
/>
<ProgressBar
android:max="100"
android:progress="50"
android:secondaryProgress="80"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar3"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/progressBar2"
android:layout_marginBottom="81dp"
android:layout_alignTop="@+id/res"
android:progressDrawable="@layout/progress"/><!--progressDrawable改变样式-->
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar4"
android:layout_above="@+id/reset"
android:layout_centerHorizontal="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/增加"
android:id="@+id/add"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/减少"
android:id="@+id/res"
android:layout_above="@+id/add"
android:layout_alignParentEnd="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/重置"
android:id="@+id/reset"
android:layout_alignBottom="@+id/progressBar3"
android:layout_alignParentEnd="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="进度"
android:id="@+id/textView"
android:layout_below="@+id/progressBar"
android:layout_alignParentEnd="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/显示进度条"
android:id="@+id/show"
android:layout_below="@+id/progressBar2"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>
<!--
ProgressBar关键属性
1.android:max
---最大显示进度
2.android:progress
---第一显示进度
3.android:secondaryProgress---第二显示进度
4.android:isdeterminate
---设置是否精确显示(false为精确,true为不精确)-->layout中progress.xml<?xml
version="1.0"
encoding="utf-8"?>
<layer-list
xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<item
android:id="@android:id/background">
<shape>
<corners
android:radius="5dip"
/>
<gradient
android:startColor="#76cf76"
android:centerColor="#125912"
android:centerY="0.75"
an
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2021年春4月自考经管类本科电子商务概论考题含解析
- 2022年甘肃省静宁县重点达标名校中考化学对点突破模拟试卷含解析
- 2021-2022学年江西省吉安市吉安县中考二模化学试题含解析
- 2022年辽宁省大石桥市金桥管理区初级中学中考化学四模试卷含解析
- 2021-2022学年安徽省铜陵市第四中学中考化学押题试卷含解析
- 北京四中2022年中考联考化学试题含解析
- 2022届北京市海淀区第二十中学中考试题猜想化学试卷含解析
- 2022届重庆西师附中中考化学最后冲刺模拟试卷含解析
- 高血压危象的心理干预与康复支持
- 2022届来宾市重点中学中考化学四模试卷含解析
- 要下雨了教案省公开课一等奖新名师优质课比赛一等奖课件
- 病历复制授权委托书
- 高温合金A286及GH2132应用解析
- 项目式学习在初中化学复习课的实践与思考
- 云南省高中数学学业水平考试考点与试题分类汇编教学课件
- 桡动脉置管技术操作SOP
- 学前幼儿园-4八仙过海的传说教学课件设计
- 会计师事务所资产评估机构薪酬制度
- 口腔诊所常见设备器械的保养维修
- 2023年广东珠海中考语文真题及答案
- 2023年汉字听写大会汉字听写知识竞赛题库及答案(共三套)
评论
0/150
提交评论