zoukankan      html  css  js  c++  java
  • 安卓学习-界面-ui-ProcessBar

    ProcessBar

    属性 方法 说明
     android:max  setMax(int max)   最大值
     android:progress  setProgress(int progress)  进度
     android:progressDrawable  setProgressDrawable(Drawable d)  轨道图片
     android:indeterminate  setIndeterminate(boolean indeterminate)  进度是否确定,常用在不确定进度,但是有需要进度效果的
     android:indeterminateDrawable  setIndeterminateDrawable(Drawable d)  不确定进度的轨道图片
     android:indeterminateDuration  

     不确定进度的持续时间

    设置了没效果

    例子1

    没1秒,增加1,最大100

    activity_main.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="10dp" >
    
        <ProgressBar
            android:id="@+id/ProgressBar1"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:max="100" />
    
    </LinearLayout>
    View Code

    MainActivity.java

    public class MainActivity extends Activity{
    
        ProgressBar progressBar1;
        int proc=0;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            progressBar1=(ProgressBar)findViewById(R.id.ProgressBar1);
            
            new Thread(){
                @Override
                public void run() {
                    while(proc<100){
                        proc=proc+1;
                        try {
                            sleep(1000);
                            handler.sendEmptyMessage(123);
    
                        } catch (InterruptedException e) {
                            // TODO 自动生成的 catch 块
                            e.printStackTrace();
                        }
                        
                    }               
                    
                }
                
            }.start();
        }
        
        Handler handler=new Handler(){
            @Override
            public void handleMessage(Message msg) {
                if(msg.what==123){
                    progressBar1.setProgress(proc);
                }
            }
            
        };
    
    }
    View Code

     例子2

    显示在标题上的进度条

    需要说明的是标题的进度条是从0-10000的,而且最大值是不能设置的

    activity_main.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:padding="10dp" >
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="显示" />
    
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="隐藏" />
    
    </LinearLayout>
    View Code

    MainActivity.java

    public class MainActivity extends Activity{
    
        Button btn1;
        Button btn2;
    
        int proc=0;
        
        Thread thread;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            
          //带进度条的 
          requestWindowFeature(Window.FEATURE_PROGRESS);
          //不带
          requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
            
            setContentView(R.layout.activity_main);
            
            btn1=(Button)findViewById(R.id.button1);
            btn2=(Button)findViewById(R.id.button2);
            
            thread=new Thread(){
                @Override
                public void run() {
                    while(proc<10000){
                        proc=proc+1000;
                        try {
                            sleep(1000);
                            handler.sendEmptyMessage(123);
    
                        } catch (InterruptedException e) {
                            // TODO 自动生成的 catch 块
                            e.printStackTrace();
                        }
                        
                    }               
                    
                }
                
            };
            
            btn1.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
                    setProgressBarIndeterminateVisibility(true);
                    setProgressBarVisibility(true);
                    
                    thread.start();
                
                }
            });
            
            btn2.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    setProgressBarIndeterminateVisibility(false);
                    setProgressBarVisibility(false);
                    
                }
            });
    
    
        }
        
        Handler handler=new Handler(){
            @Override
            public void handleMessage(Message msg) {
                if(msg.what==123){
                    MainActivity.this.setProgress(proc);
                }
            }
            
        };
    
    }
    View Code
  • 相关阅读:
    模板 无源汇上下界可行流 loj115
    ICPC2018JiaozuoE Resistors in Parallel 高精度 数论
    hdu 2255 奔小康赚大钱 最佳匹配 KM算法
    ICPC2018Beijing 现场赛D Frog and Portal 构造
    codeforce 1175E Minimal Segment Cover ST表 倍增思想
    ICPC2018Jiaozuo 现场赛H Can You Solve the Harder Problem? 后缀数组 树上差分 ST表 口胡题解
    luogu P1966 火柴排队 树状数组 逆序对 离散化
    luogu P1970 花匠 贪心
    luogu P1967 货车运输 最大生成树 倍增LCA
    luogu P1315 观光公交 贪心
  • 原文地址:https://www.cnblogs.com/weijj/p/3960745.html
Copyright © 2011-2022 走看看