<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ProgressBar
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/pb"
/>
<!--进度条-->
<Button
android:layout_width="200dp"
android:layout_height="100dp"
android:text="显示隐藏进度条"
android:onClick="leoClick"
/>
<ProgressBar
android:layout_width="200dp"
android:layout_height="200dp"
android:max="100"
style="?android:attr/progressBarStyleHorizontal"
/>
<!--style设置水平进度条-->
</androidx.constraintlayout.widget.ConstraintLayout>
java代码:
package com.example.progressbar;
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressbar=findViewById(R.id.pb);
}
public void leoClick(View view){
if(progressbar.getVisibility()==View.GONE)//如果progressbar当前隐藏
{
progressbar.setVisibility(View.VISIBLE);//显示当前progressbar
}
else{
progressbar.getVisibility(View.GONE);
}
}
}
标签:layout,progressbar,height,200dp,android,ProgressBar,View From: https://www.cnblogs.com/fengjiale/p/17157402.html