ProgressBar
常用属性详解
- android:max :进度条的最大值
- android:progress;进度条已完成进度值
- android:indeterminate: 如果设置成true,则进度条不精确显示进度
- stytle="?android:attr/progressBarStyleHorizontal" 水平进度条
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ProgressBar
android:id="@+id/pb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="显示隐藏进度条"
android:onClick="MyClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ProgressBar
android:id="@+id/pb2"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:max="100"
android:layout_width="300dp"
android:indeterminate="true"
android:layout_height="wrap_content"/>
<Button
android:text="模拟下载"
android:onClick="Load"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
package com.example.myprogressbar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
private ProgressBar progressBar;
private ProgressBar progressBar2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = findViewById(R.id.pb);
progressBar2 = findViewById(R.id.pb2);
}
public void MyClick(View view) {
if(progressBar.getVisibility() == View.GONE){
progressBar.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.GONE);
}
}
public void Load(View view) {
int progress = progressBar2.getProgress();
progress += 10;
progressBar2.setProgress(progress);
}
}
![MyProgreeBar](https://i-blog.csdnimg.cn/blog_migrate/00c7ce7b7a110073a199cdca11c28e10.jpeg)