ProgressBar进度条示例

//ProgressBar示例
-------------
MainActivity.java
--------------
package com.example.gby.s01_e17_progressbar;

import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {

    private ProgressBar progressBar;
    private Button firstButton;
    private Button secondButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        progressBar = (ProgressBar)findViewById(R.id.firstProgressBar);//找对象
        firstButton = (Button)findViewById(R.id.firstButton);//找对象
        secondButton = (Button)findViewById(R.id.secondButton);//找对象

        progressBar.setMax(100);

        firstButton.setOnClickListener(new FirstListener());//必须new个对象
        secondButton.setOnClickListener(new SecondListener());//必须new个对象
//        boolean flag = progressBar.isIndeterminate();//是 非精确的,就是转圈的进度条
//        progressBar.incrementProgressBy(10);//增量进度
//        progressBar.incrementSecondaryProgressBy(10);
    }
    class FirstListener implements View.OnClickListener{
        @Override
        public void onClick(View view) {
            progressBar.incrementProgressBy(10);
        }
    }
    class SecondListener implements View.OnClickListener{
        @Override
        public void onClick(View view) {
            progressBar.incrementSecondaryProgressBy(20);
        }
    }
}

---------------
activity_main.xml
----------------
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context="com.example.gby.s01_e17_progressbar.MainActivity">

    <ProgressBar
        android:id="@+id/firstProgressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?android:attr/progressBarStyleHorizontal"
        />
    <Button
        android:id="@+id/firstButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/firstProgressBar"
        android:text="增加第一进度"
        />
    <Button
        android:id="@+id/secondButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/firstButton"
        android:text="增加第二进度"
        />
</RelativeLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值