본문 바로가기
Programing/android

[android] 다이얼로그 로딩 화면 구현, loading...중 화면 만들기.

by TEXTBOX 2021. 11. 18.
728x90

 

위 이미지 처럼 백그라운드 작업이 진행될 동안 화면에 표시될 로딩 다이얼로그를 만들어 보자.
오늘의낚시 컨디션을 보여줄 앱에 로딩화면을 추가해 주었다.

일단 github에서 이쁜 로딩이미지로 사용할 라이브러리를 찾아보았다.
아래 링크의 라이브러리를 이용하기로 하였다.

https://github.com/ybq/Android-SpinKit

 

GitHub - ybq/Android-SpinKit: Android loading animations

Android loading animations. Contribute to ybq/Android-SpinKit development by creating an account on GitHub.

github.com

 

라이브러리 안에 다양한 로딩이미지가 있었다.

나는 맨 아래 노란색으로 되어 있는 로딩이미지를 사용하였다.
찾아보니 이름이 [PulseRing]이였다.

라이브러리의 안내대로 먼저 Gradle dependencies에 아래와 같이 추가를 해준다.

dependencies {
   implementation 'com.github.ybq:Android-SpinKit:1.4.0'
}

 

progress를 나타내어 줄 Layout을 만들자.

파일 이름은 [dialog_progress.xml]로 만들어 주었다.
그리고 라이브러리에 나와있는데로 SpinKitView를 아래와 같이 추가해 주고 로딩이미지밑에 설명을
덪붙여 줄 TextView도 추가해 주었다.

    <com.github.ybq.android.spinkit.SpinKitView
        android:id="@+id/spin_kit"
        style="@style/SpinKitView.Large.Circle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        app:SpinKit_Color="@color/bg_progress"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        android:text="낚시지수를 가져오는 중입니다..."
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/spin_kit" />

 

그리고 나서 로딩 다이얼로그를 보여줄 파일을 만들자.

이름은 [ProgressDialog]로 만들었다.
그리고 만든 후 라이브러리 참조대로 아래 코드를 추가해 주었다.

public class ProgressDialog extends Dialog {
    public ProgressDialog(@NonNull Context context) {
        super(context);

        requestWindowFeature(Window.FEATURE_NO_TITLE); //title 없이
        setContentView(R.layout.dialog_progress);

		//라이브러리 로딩이미지 사용
        ProgressBar progressBar = (ProgressBar)findViewById(R.id.spin_kit);
        Sprite pulseRing = new PulseRing();
        progressBar.setIndeterminateDrawable(pulseRing);


    }
}

 

이제 다이얼로그를 다 만들었으니 앱에서 실행되는동안 다이얼로그를 띄워주면 끝이다.
로딩 다이얼로그를 띄어줄 화면에서 아래 명령어를 실행해 띄어주면 된다.

ProgressDialog progressDialog = new ProgressDialog(this); //다이얼로그 선언
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); //백그라운를 투명하게
progressDialog.setCancelable(false); //다이얼로그 외부 클릭으로 종료되지 않게

progressDialog.show(); //로딩화면 보여주기

그리고 처리될 메소드들이 다 처리되고 나면 아래와 같이 종료를 해주면 된다.

progressDialog.dismiss();	//progress dialog 종료

 

그럼 아래와 같이 작업중일때 나타낼 수 있다.

 

끝~~~!!

728x90

댓글