ProgressBar
作者:互联网
常用属性详解
-
android:max:进度条最大值
-
android:progress:进度条已完成进度值
-
android:indeterminate:如果设置成true,则进度条不精确显示进度
-
style="?android:attr/progressBarStyleHorizontal"水平进度条
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/pb_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/pb_btn_1"
android:text="显示隐藏进度条"
android:onClick="onClick1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ProgressBar
android:id="@+id/pb_2"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:layout_width="300dp"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/pb_btn_2"
android:text="模拟下载"
android:onClick="onClick2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:indeterminate="true"
android:layout_width="300dp"
android:layout_height="wrap_content"/>
</LinearLayout>
显示隐藏进度条,模拟下载进度
package com.example.projet01;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
public class ProgressBarActivity extends AppCompatActivity {
private ProgressBar mPb1;
private ProgressBar mPb2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_progress_bar);
mPb1 = findViewById(R.id.pb_1);
mPb2 = findViewById(R.id.pb_2);
}
public void onClick1(View view) {
if(mPb1.getVisibility() == View.GONE){//当进度条为隐藏时
mPb1.setVisibility(View.VISIBLE);//点击显示
}else {
mPb1.setVisibility(View.GONE);//否则为隐藏
}
}
public void onClick2(View view) {
int progress = mPb2.getProgress();
progress += 10;
mPb2.setProgress(progress);
}
}
标签:layout,进度条,ProgressBar,content,wrap,android,id 来源: https://www.cnblogs.com/qiezi01/p/15155324.html