xml文件:

<LinearLayout 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"
android:orientation="vertical"
tools:context="com.example.progressbar.MainActivity" >
<!-- progressBar 进度条
分为圆形进度条和水平进度条
圆形进度条又分为小,中,大型进度条
属性:
style 指定进度条的类型,有如下值:
@android:style/Widget.ProgressBar.Small 小圆型进度条
@android:style/Widget.ProgressBar 中圆型进度条
@android:style/Widget.ProgressBar.Large 大圆型进度条
@android:style/Widget.ProgressBar.Horizontal 水平进度条
-->
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Small" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Large" />
<!-- 水平进度条的属性
android:max 最大值
android:progress 当前值 -->
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:max="100"
android:progress="10"
style="@android:style/Widget.ProgressBar.Horizontal" /> <SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"/> </LinearLayout>

源代码:

package com.example.progressbar;

import java.util.Timer;
import java.util.TimerTask; import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ProgressBar;
import android.widget.SeekBar; public class MainActivity extends Activity {
ProgressBar progressBar;
SeekBar seekBar;
private int progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setProgress(progress);
//创建定时器
Timer timer = new Timer();
//设置定时器的任务
//参数一:时间到的时候执行的任务
//参数2:第一次延迟多久后执行任务(单位:ms)
//参数3:每隔多久执行一次任务(单位:ms)
TimerTask task = new MyTimerTask();
timer.schedule(task,3000,1000);
//获取拖动条
seekBar = (SeekBar) findViewById(R.id.seekBar);
//给拖动条添加拖动事件
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
//停止拖动时调用
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
Log.i("MainActivity", "停止拖动");
}
//开始拖动时调用
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub }
//正在拖动时调用
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub }
});
} public class MyTimerTask extends TimerTask{ @Override
public void run() {
// TODO Auto-generated method stub
progress += 5;
if(progress >= progressBar.getMax()){
progress = progressBar.getMax();
}
progressBar.setProgress(progress);
} } }

Android_SeekBarAndProgressBar的更多相关文章

随机推荐

  1. 【HDOJ】3509 Buge's Fibonacci Number Problem

    快速矩阵幂,系数矩阵由多个二项分布组成.第1列是(0,(a+b)^k)第2列是(0,(a+b)^(k-1),0)第3列是(0,(a+b)^(k-2),0,0)以此类推. /* 3509 */ #inc ...

  2. poj2029Get Many Persimmon Trees(最大矩阵和)

    链接 类似最大矩阵 sum存下 枚举最大就是 #include <iostream> #include<cstdio> #include<cstring> #inc ...

  3. Webform——验证控件

    验证控件一般是在注册的时候用到,是直接将JS代码封装到了控件里面,拉过来直接可以用,下面介绍一下主要用法: 1.CompareValidator:比较验证 常用属性:ControlToCompare ...

  4. DMG提取安装文件

    打开原版的DMG文件,选中安装文件,按下鼠标右键,选择显示包内容 <ignore_js_op> 按照下图的路径,一直找到installESD.dmg,双击打开它<ignore_js_ ...

  5. C# Word 类库的深入理解

    using System;using System.Collections.Generic;using System.Text;using Microsoft.Office.Interop.Word; ...

  6. GPIO

    一.什么是GPIO?       首先应该理解什么是GPIO.GPIO,英文全称为General-Purpose IO ports,也就是通用IO口.在嵌入式系统中常常有数量众多,但是结构却比较简单的 ...

  7. vs212创建mvc3项目,添加ADO.NET实体数据模型时产生 XXXX.Desiger.cs 文件为空

    vs212创建mvc3项目,发现添加ADO.NET实体数据模型时,产生StoreDB.Desiger.cs文件为空 产生StoreDB.Desiger.cs文件为空 原因是,在vs2012中,添加AD ...

  8. Linux查看系统版本信息的

    // 显示电脑以及操作系统的相关信息 uname -a // 正在运行的内核版本 cat /proc/version // 显示的是发行版本信息 cat /etc/issue // 适用于所有的lin ...

  9. 【CSS】Beginner3:Color

    1.red rgb(255,0,0) rgb(100%,0%,0%) #ff0000 #f00 2.Predefined color name aqua, black, blue, fuchsia, ...

  10. (原)Struts 相关资源下载

    官网:http://struts.apache.org 点击[Download],进入页面如下,可以看到下载的资源: 点击[struts-2.3.20-all.zip],就能获取Struts2项目所有 ...