一.ProgressBar的样式

在XML中的第一种写法:
style="?android:attr/progressBarStyleSmallTitle"
style="?android:attr/progressBarStyleLargeInverse"
style="?android:attr/progressBarStyleLarge"
style="?android:attr/progressBarStyleInverse"
style="?android:attr/progressBarStyleSmall"
style="?android:attr/progressBarStyleHorizontal"
style="?android:attr/progressBarStyle"
style="?android:attr/progressBarStyleSmallInverse"
style="?android:attr/progressBarPadding"
在XML中的第二种写法:
Widget.ProgressBar.Horizontal

剩余的省略


二.ProgressBar的一些常用属性
Android:max    滚动条最大值
android:progress滚动条当前值
android:visibility  滚动条是否可见
android:indeterminate="true"  控制ProgressBar是否是确定的  (determinate英文意思确定的,indeterminate不确定的)
android:secondaryProgress属性是主要是为了缓存需要所涉及的,比如看视频的时候都会有一个播放进度和一个缓存进度,
 这个缓存进度就是 android:secondaryProgress属性所对应的值,播放进度就是android:progress属性对应的值

三.ProgressBar的一些常见的方法
isIndeterminate():指示进度条是否在不确定模式下
setIndeterminate(boolean indeterminate):设置不确定模式下
onSizeChanged(int w, int h, int oldw, int oldh):当进度值改变时引发此事件
setProgressBarIndeterminateVisibility(boolean value)在代码中设置进度条是否可见
setProgress(int)设置当前进度值
incrementProgressBy(int)设置当前进度值的增量(正数为增,负数为减)
setSecondaryProgress(int)设置缓存进度条进度值
incrementSecondaryProgressBy(int)设置缓存进度条进度值的增量(正数为增,负数为减)
progressBar.incrementProgressBy(5);//ProgressBar进度值增加5
progressBar.incrementProgressBy(-5);//ProgressBar进度值减少5
progressBar.incrementSecondaryProgressBy(5);//ProgressBar缓存进度条进度值增加5

progressBar.incrementSecondaryProgressBy(-5);//ProgressBar缓存进度条进度值减少5


四.ProgressBar的子类
ProgressBar的直接子类是AbsSeekBar和ContentLoadingProgressBar

AbsSeekBar的子类有SeekBar和RatingBar

SeekBar和RatingBar在这先不作介绍。


五.ProgressBar的Demo
package com.outdoors.jinghuang.demo;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

import android.widget.TextView;


/**
 * Created by jing.huang on 2016/12/2.
 */
public class ProgressBarDemo extends Activity implements View.OnClickListener {

    private ProgressBar progressBar;
    private TextView showProgressDetail;
    private Button startBt;
    private static final int INCREMENT_PROGRESS = 1003;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.progress_bar_demo);
        initView();
        initData();
    }

    private void initView() {
        progressBar = (ProgressBar) findViewById(R.id.progress);
        showProgressDetail = (TextView) findViewById(R.id.show_progress_detail);
        startBt = (Button) findViewById(R.id.start_bt);
        startBt.setOnClickListener(this);
    }

    private void initData() {
        //设置progress的初始值
        progressBar.setProgress(0);
        //设置ProgressBar的最大值
        progressBar.setMax(100);
        //设置progressBar为确定的
        progressBar.setIndeterminate(false);
        progressBar.setVisibility(View.GONE);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.start_bt) {
            startBt.setClickable(false);
            progressBar.setVisibility(View.VISIBLE);
            //每次点击按钮都级那个数据初始化
            progressBar.setProgress(0);
            showProgressDetail.setText("当前进度为:" + progressBar.getProgress());
            dealProgress();
        }
    }

    /**
     * 处理进度
     */
    private void dealProgress() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (progressBar.getProgress() < progressBar.getMax()) {
                    //设置progress每次增长5
                    progressBar.incrementProgressBy(5);
                    //设置SecondaryProgress每次增长10
                    progressBar.incrementSecondaryProgressBy(10);
                    Message message = handler.obtainMessage();
                    message.what = INCREMENT_PROGRESS;
                    handler.sendMessage(message);
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case INCREMENT_PROGRESS:
                    showProgressDetail.setText("当前进度为:" + progressBar.getProgress());
                    if (progressBar.getProgress() == progressBar.getMax()) {
                        startBt.setClickable(true);
                        progressBar.setVisibility(View.GONE);
                    }
                    break;
                default:
                    break;
            }
        }
    };
}







更多相关文章

  1. android Progress style (长进度条)
  2. Android 学习笔记(十六):Widget-进度条
  3. Android进度条源代码
  4. android的进度条相关知识
  5. 2.5.6 使用progressDialog创建进度对话框
  6. android进度对话框的使用
  7. Android 进度条
  8. android进度条的样式
  9. Android用户界面UI组件--AdapterView及其子类(四) GridView

随机推荐

  1. 苹果Mac如何关闭右上角的Siri显示?
  2. Cisco ISE如何关机-----ISE的关机方法和
  3. 从事运维工作是一种怎样的体检?
  4. 苏宁大数据离线任务开发调度平台实践:任务
  5. 逻辑复制-更改复制标识(REPLICA IDENTITY)
  6. Prometheus 之 Kubernetes节点的监控
  7. 帆软和思迈特软件Smartbi产品的详细对比
  8. Linux运维入门教程06-04 (硬盘分区、格式
  9. 百家号在线视频编辑器的技术演进
  10. python3函数中lambda/filter/map/reduce