Android
[Android-] ProgressBar & Slider
연나연
2024. 1. 23. 14:34
1. ProgressBar

ProgressBar
오래 걸리는 작업이 있을 경우 작업 중임을 표시하는 View
근데 사실 progressbar를 넣는게 중요한게 아니라 progresbar가 필요하지 않게끔 빠른 작업을 주는게 젤 중요하다 !
<!-- Linear progress indicator --> <com.google.android.material.progressindicator.LinearProgressIndicator android:layout_width="match_parent" android:layout_height="wrap_content" /> <!-- Circular progress indicator --> <com.google.android.material.progressindicator.CircularProgressIndicator android:layout_width="wrap_content" android:layout_height="wrap_content" />
[ LinearProgressIndicator ]
1. 주요 속성 - indeterminate : true로 주면 애니메이션이 계속 나오는 상태로 보여진다.
2. 주요 프로퍼티 - progress : 현재 진행바의 크기를 설정해준다. 최소0, 최대 100
3. 주요 메서드 - setProgress : 현재 진행바의 크기를 설정해준다. 두 번째 매개변수에 true를 넣어주면 애니메이션 효과가 나타난다.
실습해보자
package kr.co.lion.android19_progressslider import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import kr.co.lion.android19_progressslider.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { lateinit var activityMainBinding : ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) activityMainBinding = ActivityMainBinding.inflate(layoutInflater) setContentView(activityMainBinding.root) activityMainBinding.apply { button.setOnClickListener { // progressIndicator의 값을 설치한다 // progressBar.progress += 10 progressBar.setProgress(progressBar.progress + 10, true) } button2.setOnClickListener { // progressIndicator의 값을 가져온다 textView.text = "progree value : ${progressBar.progress}" } } } }<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" android:orientation="vertical" tools:context=".MainActivity" > <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="TextView" android:textAppearance="@style/TextAppearance.AppCompat.Large" /> <com.google.android.material.progressindicator.LinearProgressIndicator android:id="@+id/progressBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" /> <com.google.android.material.progressindicator.LinearProgressIndicator android:id="@+id/progressBar2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:indeterminate="true" /> <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Progress 증가" /> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Progredd 값 가져오기" /> </LinearLayout>
2. Slider
Slider
1. 주소 속성
- valueFrom : 최소 값
- valueTo : 최대 값
실습button3.setOnClickListener { slider.value = 80.0f } button4.setOnClickListener { textView.text = "slider value : ${slider.value}" }<com.google.android.material.slider.Slider android:id="@+id/slider" android:layout_width="match_parent" android:layout_height="wrap_content" android:value="30.0" android:valueFrom="0.0" android:valueTo="100.0" /> <com.google.android.material.slider.Slider android:id="@+id/slider2" class="com.google.android.material.slider.Slider" android:layout_width="match_parent" android:layout_height="wrap_content" android:stepSize="10.0" android:value="30.0" android:valueFrom="0.0" android:valueTo="100.0" /> <Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="slidet 값 세팅" /> <Button android:id="@+id/button4" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="slider 값 가져오기" />

