阅读《Android 从入门到精通》(17)——进度条
进度条(ProgressBar)
java.lang.Object;
android.view.View;
android.widget.ProgressBar;
ProgressBar 类方法
ProgressBar 演示样例
完整project:http://download.csdn.net/detail/sweetloveft/9416791
以下我们要学习该类中最经常使用的方法。主要是 setMax 和 setProgress 等方法。
1.MainActivity.java
package com.sweetlover.activity; import com.sweetlover.progressbar.R; import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); final ProgressBar progressHorizontal = (ProgressBar) findViewById(R.id.progress_horizontal);
setProgress(progressHorizontal.getProgress() * 100);
setSecondaryProgress(progressHorizontal.getSecondaryProgress() * 100); Button button = (Button) findViewById(R.id.increase);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementProgressBy(1);
// Title progress is in range 0..10000
setProgress(100 * progressHorizontal.getProgress());
}
}); button = (Button) findViewById(R.id.decrease);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementProgressBy(-1);
// Title progress is in range 0..10000
setProgress(100 * progressHorizontal.getProgress());
}
}); button = (Button) findViewById(R.id.increase_secondary);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementSecondaryProgressBy(1);
// Title progress is in range 0..10000
setSecondaryProgress(100 * progressHorizontal.getSecondaryProgress());
}
}); button = (Button) findViewById(R.id.decrease_secondary);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementSecondaryProgressBy(-1);
// Title progress is in range 0..10000
setSecondaryProgress(100 * progressHorizontal.getSecondaryProgress());
}
});
}
}
2.activity_main.xml
<? xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="30dp" > <ProgressBar android:id="@+id/progress_horizontal"
style="? android:attr/progressBarStyleHorizontal"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:max="100"
android:progress="50"
android:secondaryProgress="75" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="@string/normal" /> <LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="20dp" > <Button
android:id="@+id/decrease"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/decrease" /> <Button
android:id="@+id/increase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/increase" /> </LinearLayout> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="@string/custom" /> <LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="20dp" > <Button
android:id="@+id/decrease_secondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/decrease" /> <Button
android:id="@+id/increase_secondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/increase" /> </LinearLayout> </LinearLayout>
3.strings.xml
<resources>
<string name="app_name">ProgressBar</string>
<string name="normal">默认进度条</string>
<string name="decrease">降低</string>
<string name="increase">添加</string>
<string name="custom">自己定义进度条</string>
</resources>
4.AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sweetlover.progressbar"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name="com.sweetlover.activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application> </manifest>
阅读《Android 从入门到精通》(17)——进度条的更多相关文章
- Android从入门到精通pdf+书源代码
不须要积分,免费放送 Android从入门到精通的pdf,入门的好书籍,因为csdn文件大小的限制所以分成了两部分. part1地址:http://download.csdn.net/detail/a ...
- Android开发-各种各样好看漂亮的进度条,指示器,加载提示汇总
导读:之前项目中用到一些进度条,找了不少,打算写个demo自己总结一下,留着以后用, 有些是自己写的,有些是github上找的别人的库,如果大家觉得好看可以用,直接下载复制代码到项目里就可以用,ok ...
- android 自定义控件——(四)圆形进度条
----------------------------------↓↓圆形进度条(源代码下有属性解释)↓↓---------------------------------------------- ...
- android 网络异步加载数据进度条
ProgressDialog progressDialog = null; public static final int MESSAGETYPE = 0; private void execute( ...
- Android Volley入门到精通:使用Volley加载网络图片
在上一篇文章中,我们了解了Volley到底是什么,以及它的基本用法.本篇文章中我们即将学习关于Volley更加高级的用法,如何你还没有看过我的上一篇文章的话,建议先去阅读Android Volley完 ...
- Android自己定义控件:进度条的四种实现方式
前三种实现方式代码出自: http://stormzhang.com/openandroid/2013/11/15/android-custom-loading/ (源代码下载)http://down ...
- 每天一点Android干货-时间与日期、进度条
时间控件TimePicker的使用方法 timePicker.setIs24HourView(true); //设置是否以24小时制显示 timePicker.getCurrentHour(); // ...
- android 开发 制作弹出等待进度条
技术点: dialog:ProgressBar:animated-rotate: 弹出框: import com.carspeak.client.R; import android.app.Dialo ...
- android AsyncTask异步下载并更新进度条
AsyncTask异步下载并更新进度条 //如果不是很明白请看上篇文章的异步下载 AsyncTask<String, Integer, String> 第一个参数:String 传入 ...
随机推荐
- MongoDB学习笔记(二)--Capped集合 && GridFS存储文件
Capped集合 Capped集合的大小是固定的,如果空间都被用完了,新添加的对象 ...
- WebRequest多线程 超时问题
using System; using System.Collections; using System.Collections.Generic; using System.Net; using Sy ...
- https://leetcode-cn.com/
https://leetcode-cn.com/ 码,马不停蹄,码不停题 英文版:https://leetcode.com/
- HDU 1495 很可乐 (DFS)
题目链接:很可乐 解析:一个瓶子,容量为s.两个杯子,容量分别为n和m,问最少多少次倾倒才干将一瓶可乐均分为两份. 直接模拟每次的倾倒.然后递归求解. 能够加个预判的条件,要是s是奇数的时候,不管怎样 ...
- 解决Windows Git Bash中文乱码问题
在git 安装目录 etc 下面 添加以下配置信息 1,/etc/gitconfig: [gui] encoding = utf-8 #代码库统一用urf-8,在git gui中可以正常显示中文 [i ...
- 12款程序员们最爱的Bootstrap模板
如果你还没有开始使用Bootstrap模板,那你可真是有够OUT,这是一个帮助你快速开发的工具,Bootstrap是基于jQuery框架开发的,它在jQuery框架的基础上进行了更为个性化和人性化的完 ...
- DigCSDN介绍首页
recrefer=SE_D_DigCSDN">360手机助手下载地址 兴许平台会陆续登陆上线的,大家敬请期待 最后由于屏幕适配和分享链接的问题,导致最后的公布时间延误了好几天--- 今 ...
- JBOSS启动报错解决方案
同一个jboss下不可以放不同的项目包,否则报错: 注意:如果后期使用,注意删除上图的本地文件,重新加载即可.
- windows下npm默认的全局路径
C:\Users\用户名\AppData\Roaming\npm\node_modules
- LightOj 1123-Trail Maintenance(最小生成树:神级删边)
1123 - Trail Maintenance PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB ...