Android的ProgressBar进度条-android学习之旅(三十一)

ProgressBar 简介

ProgressBar是一种很常用的Ui,用于给复杂的操作显示进度,提供更好的用户相应。使用setProgress()incrementProgressBy()来设置进度和显示进度的增加或减少,正数表示增加,负数表示减少。

ProgressBar的风格

ProgressBar

代码示例

布局代码

<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="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"
            />
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@android:style/Widget.ProgressBar.Large"/>
        </LinearLayout>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="下面是水平的进度条"/>
    <ProgressBar
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/bar"
        android:max="100"
    style="@android:style/Widget.ProgressBar.Horizontal"/>
    <ProgressBar
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bar2"
        android:max="100"
        android:progressDrawable="@drawable/bar"
        style="@android:style/Widget.ProgressBar.Horizontal"/>
</LinearLayout>
<?xml version="1.0" encoding="UTF-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:id="@android:id/background"
            android:drawable="#f00"
            />
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/ic_launcher"/>
    </layer-list>

主体类代码

package peng.liu.testview;

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

public class MainActivity extends Activity {
    private int[] data = new int[100];
    int hasData = 0;
    int status = 0;
    ProgressBar bar,bar2;
    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if(msg.what == 0x123){
                bar.setProgress(status);
                bar2.setProgress(status);
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bar = (ProgressBar) findViewById(R.id.bar);
        bar2 = (ProgressBar) findViewById(R.id.bar2);
        new Thread(){
            @Override
            public void run() {
               if(status < 100){
                   status = dowork();
                   handler.sendEmptyMessage(0x123);
               }
            }
        };
    }
    public int dowork(){
        data[hasData++] = (int) (Math.random()*100);
        try{
            Thread.sleep(100);
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return hasData;
    }
}

效果图

时间: 2024-08-03 07:08:29

Android的ProgressBar进度条-android学习之旅(三十一)的相关文章

Android View 之进度条+拖动条+星级评论条....

PS:将来的你会感谢现在奋斗的自己.... 学习内容: 1.进度条 2.拖动条 3.星级评论条 1.进度条...       进图条这东西想必大家是很熟悉的...为了使用户不会觉得应用程序死掉了,因此为之设置一个进度条使应用程序的运行状态更好的反馈给客户...这也就是进度条的作用...因此一般的应用程序都会加入进度条...进度条分为圆形进度条和线性的进度条...目的都是一样的,只是展示的效果是不同的...用代码讲解一下... <LinearLayout xmlns:android="htt

Android学习笔记_76_Android ProgressBar 进度条

android 进度条的样式  例1:(默认样式(中等圆形))Xml代码 <ProgressBar      android:id="@+id/progressBar1"     android:layout_width="wrap_content"      android:layout_height="wrap_content"      /> 例2:(超大圆形)Xml代码 <ProgressBar      android

Android 学习心得(6)——ProgressBar(进度条)

没什么技术含量就是对系统进度条的简单应用 贴上代码 1 package cn.bwl.progressbar; 2 3 import android.support.v7.app.ActionBarActivity; 4 import android.view.View; 5 import android.widget.Button; 6 import android.widget.ProgressBar; 7 import android.widget.TextView; 8 import a

Android基础入门教程——2.3.7 ProgressBar(进度条)

Android基础入门教程--2.3.7 ProgressBar(进度条) 标签(空格分隔): Android基础入门教程 本节引言: 本节给大家带来的是Android基本UI控件中的ProgressBar(进度条),ProgressBar的应用场景很多,比如 用户登录时,后台在发请求,以及等待服务器返回信息,这个时候会用到进度条:或者当在进行一些比较 耗时的操作,需要等待一段较长的时间,这个时候如果没有提示,用户可能会以为程序Carsh或者手机死机 了,这样会大大降低用户体验,所以在需要进行耗

android之实现ProgressBar进度条组件

android之实现ProgressBar进度条组件: (注意:横向那个进度条要android4.0以上版本支持,也就是最低(android:minSdkVersion="14")支持) 布局:layout/activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.a

Android -- ProgressBar(进度条的使用)

我们在开发程序是经常会需要软件全屏显示.自定义标题(使用按钮等控件)和其他的需求,今天这一讲就是如何控制Android应用程序的窗体显示. requestWindowFeature可以设置的值有:(具体参考 点击链接查看效果)    1.DEFAULT_FEATURES:系统默认状态,一般不需要指定        // 2.FEATURE_CONTEXT_MENU:启用ContextMenu,默认该项已启用,一般无需指定        // 3.FEATURE_CUSTOM_TITLE:自定义标

Android基础控件ProgressBar进度条的使用

1.简介 ProgressBar继承与View类,直接子类有AbsSeekBar和ContentLoadingProgressBar, 其中AbsSeekBar的子类有SeekBar和RatingBar! android:max:进度条的最大值 android:progress:进度条已完成进度值 android:progressDrawable:设置轨道对应的Drawable对象 android:indeterminate:如果设置成true,则进度条不精确显示进度 android:indet

【转】24. android dialog ——ProgressDialog 进度条对话框详解

原文网址:http://blog.csdn.net/jamesliulyc/article/details/6375598 首先在onCreateDialog方法里创建一个ProgressDialog,如下: [java] view plaincopy //this表示该对话框是针对当前Activity的 progressDialog = new ProgressDialog(this); //设置最大值为100 progressDialog.setMax(100); //设置进度条风格STYL

Android 中带有进度条效果的按钮(Button)

安卓中带有进度条效果的按钮,如下图: 1.布局文件如下activity_main.xml 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="fill_parent" 4 android:layo