Android/Java

[Java]  ProgressBar

혀가 길지 않은 개발자 2020. 8. 7. 18:47

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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"
    android:gravity="center"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">

        <Button
            android:id="@+id/btnVisible"
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:layout_gravity="center"
            android:textAllCaps="false"
            android:text="Visible"
            android:textSize="26dp"
            android:textStyle="italic" />

        <Button
            android:id="@+id/btnGone"
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:layout_gravity="center"
            android:textAllCaps="false"
            android:text="Gone"
            android:textSize="26dp"
            android:textStyle="italic" />

    </LinearLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ProgressBar
            android:id="@+id/pbLoading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />

    </FrameLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

activity_main.xml

 

 

 

 

 

MainActivity.java

package com.jwsoft.javaproject;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {

    Button btnVisible;
    Button btnGone;
    ProgressBar pbLoading;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnVisible = findViewById(R.id.btnVisible);
        btnGone = findViewById(R.id.btnGone);
        pbLoading = findViewById(R.id.pbLoading);

        btnVisible.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pbLoading.setVisibility(View.VISIBLE);
            }
        });

        btnGone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pbLoading.setVisibility(View.GONE);
            }
        });
    }

}

실행 결과