您的位置:首页 > 移动开发 > Android开发

ProgressBar进度条示例

2016-08-25 10:37 197 查看
//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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android View