ProgressBar(进度条)的使用案例
作者:互联网
activitprogressbar.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:id="@+id/activity_progressbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.jump.ProgressbarActivity">
<ProgressBar
android:id="@+id/pb_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ProgressBar
android:id="@+id/pb_botton"
android:layout_below="@id/pb_top"
android:layout_marginTop="20dp"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="20dp"
android:max="100"/>
<Button
android:id="@+id/btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/pb_botton"
android:text="add"
android:textSize="30dp"
android:layout_marginTop="30dp"/>
</RelativeLayout>
ProgressBarActivity.java
package com.example.jump;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
public class ProgressbarActivity extends AppCompatActivity {
private Button btn_add;
private ProgressBar pb_bottom;
private int progress=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_progressbar);
intiView();
}
private void intiView(){
btn_add= (Button) findViewById(R.id.btn_add);
pb_bottom= (ProgressBar) findViewById(R.id.pb_botton);
btn_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(progress<100){
progress+=10;
pb_bottom.setProgress(progress);
}else {//进度条循环显示
progress=0;
pb_bottom.setProgress(progress);
}
}
});
}
}
标签:进度条,private,ProgressBar,案例,add,import,android,btn 来源: https://blog.51cto.com/u_15249199/2847151