zoukankan      html  css  js  c++  java
  • 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;
        }
    }
    

    效果图

    这里写图片描写叙述

  • 相关阅读:
    Python语言之并发编程
    python语言之系统工具
    python语言之正则
    python语言之字符串与字节
    Python语言之持久化
    Python语言之数字格式化与时间
    Python语言之异常处理与测试
    Java-AQS源码详解(细节很多!)
    redis的主从复制原理
    Amdahl定律和可伸缩性
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/7399550.html
Copyright © 2011-2022 走看看