android中进度条控件


进度跳控件:

ProgressBar
属性:
android:layout_width="300dp"(设置的长)
android:layout_height="50dp"(设置的高)
效果:


main.xml界面
 
  
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private ProgressBar pb_jd;
    private TextView tv_num;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        pb_jd = (ProgressBar) findViewById(R.id.pb_jd);
        tv_num = (TextView) findViewById(R.id.tv_num);

    }
    public void xz(View view){
        new MyThread().start();
    }

    Handler handler=new Handler(){
        //接收消息,更新UI界面
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            int i=msg.what;
            tv_num.setText(i+"");
        }
    };

    class MyThread extends Thread{
        @Override
        public void run() {
            super.run();
            for (int i = 0; i <= 100; i++) {
                pb_jd.setProgress(i);
                //在子线程中发消息
                handler.sendEmptyMessage(i);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }



}

效果:
 
  
 
  







你可能感兴趣的:(android中进度条控件)