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. 获取本机的ip

    https://4sysops.com/archives/ipv6-tutorial-part-6-site-local-addresses-and-link-local-addresses/ In ...

  2. TortoiseSVN设置比较工具为BeyondCompare

    1.  "C:\Beyond Compare 4\BCompare.exe" %base %mine /title1=%bname /title2=%yname /leftread ...

  3. (Deep) Neural Networks (Deep Learning) , NLP and Text Mining

    (Deep) Neural Networks (Deep Learning) , NLP and Text Mining 最近翻了一下关于Deep Learning 或者 普通的Neural Netw ...

  4. 利用switch case判断是今天的第多少天

    static void Main(string[] args)        {            while (true)            {                int m1 ...

  5. WordPress Contact Form 7插件任意文件上传漏洞

    漏洞名称: WordPress Contact Form 7插件任意文件上传漏洞 CNNVD编号: CNNVD-201311-415 发布时间: 2013-11-28 更新时间: 2013-11-28 ...

  6. NOI2010航空管制

    2008: [Noi2010]航空管制 Time Limit: 10 Sec  Memory Limit: 552 MBSubmit: 31  Solved: 0[Submit][Status] De ...

  7. SharePoint : 使用SPQuery对象时要注意的事项

    转:http://www.cnblogs.com/chenxizhang/archive/2009/10/23/1588415.html 我们经常需要对一个列表进行查询,此时最灵活的方式就是直接使用S ...

  8. 关于HTTP返回码301、302区别与SEO

    301(永久移动)请求的网页已永久移动到新位置.服务器返回此响应时,会自动将请求者转到新位置.您应使用此代码告诉搜索引擎Spider某个网页或网站已永久移动到新位置.建议在URL规范化的时候采用301 ...

  9. Get ListView items from other windows z

    This is more difficult than one might think. In order to get the information you're looking for, you ...

  10. [Irving]Android 常用布局之RelativeLayout

    RelativeLayout相对布局 相对布局 RelativeLayout 允许子元素指定它们相对于其父元素或兄弟元素的位置,这是实际布局中最常用的布局方式之一. 它灵活性大很多,当然属性也多,操作 ...