728x90
반응형
SMALL
프로그레스바 (ProgressBar)
ProgressBar는 작업의 진행 상태를 사용자에게 알려줄 때 사용하는 컴포넌트이다.
xml
<?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:id="@+id/progressBarCircle"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="76dp"
android:layout_height="76dp"
android:layout_gravity="center"
android:indeterminate="false"
android:max="100"
android:progressBackgroundTint="#D8D2D2"
android:progressDrawable="@drawable/circle_progressbar"
android:progressTint="#33D12A"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
xml : circle_progressbar
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape
android:innerRadiusRatio="2.71"
android:thicknessRatio="7.6"
android:shape="ring"
android:useLevel="false"
android:type="sweep">
<solid android:color="#9E9E9E" />
</shape>
</item>
<item android:id="@android:id/progress">
<rotate
android:fromDegrees="270"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.71"
android:thicknessRatio="7.6"
android:shape="ring"
android:angle="0"
android:type="sweep">
</shape>
</rotate>
</item>
</layer-list>
java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
private ProgressBar progressBar;
private int progressStatus = 0;
private Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBarCircle);
// Start long running operation in a background thread
new Thread(new Runnable() {
public void run() {
while (progressStatus < 100) {
progressStatus += 1;
// Update the progress bar and display the
//current value in the text view
handler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressStatus);
}
});
try {
// Sleep for 200 milliseconds.
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
}
728x90
반응형
LIST
'App Programming > Android Studio' 카테고리의 다른 글
[Android Studio] 버튼 클릭시 이미지 변경 (0) | 2022.11.04 |
---|---|
[Android Studio] 투명도 (Opacity) (0) | 2022.11.04 |
[Android Studio] Fragment (0) | 2022.10.27 |
[Android Studio] SQLite 데이터베이스 (0) | 2022.10.07 |
[Android Studio] 현재 시간, 현재 날짜 구하기 (SimpleDateFormat) (0) | 2022.09.23 |