팡세영
Log sey
팡세영
전체 방문자
오늘
어제
  • 분류 전체보기 (82)
    • PS (45)
      • programmers (13)
      • 백준 (29)
    • Android (16)
    • Daily (0)
    • Kotlin (6)
    • Design Pattern (3)
    • Java (1)
    • Flutter (3)
    • 책 리뷰 (1)
      • 클린 아키텍처 (1)
    • 공식문서 읽기 운동 (4)
      • Flutter (4)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • Android
  • 플러터
  • vercel
  • 클린아키텍처
  • 자바
  • 데이터계층
  • flutter
  • 실버
  • 안드로이드
  • 프로그래머스
  • TestCode
  • java
  • DFS
  • CustomView
  • Kotlin
  • 하단네비게이션바
  • programmers #프로그래머스
  • 골드
  • BFS
  • 문자열
  • mvvm
  • 백준
  • 해쉬맵
  • ArcitecturePattern
  • 구현
  • LEVEL2
  • 정렬
  • 단일책임원칙
  • 공식문서
  • 완전탐색

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
팡세영

Log sey

[Android ]Progress Bar - Kotlin
Android

[Android ]Progress Bar - Kotlin

2022. 7. 25. 00:44

build.gradle (Module)에서 viewBinding true 설정 


프로그래스 바를 아래와 같이 배치를 해주고 

<?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:id="@+id/parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/progressLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Downloading..." />
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.kt

UI  작업은 MainTread에서 해주어야 하기 때문에 아래와 같이 코드를 작성 합니다.

class MainActivity : AppCompatActivity() {
    val binding by lazy { ActivityMainBinding.inflate(layoutInflater)}

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)

        thread(start=true){         // 서브 스레드
            Thread.sleep(3000)

            runOnUiThread {     // 메인 스레드
                showProgress(false)
            }
        }
    }

    fun showProgress(show : Boolean){
        if(show) binding.progressLayout.visibility = View.VISIBLE
        else binding.progressLayout.visibility = View.GONE
    }
}

'Android' 카테고리의 다른 글

Android BottomNavigation Bar Round효과  (0) 2022.08.02
안드로이드 액티비티간 화면 전환 및 데이터 전달 (Intent) - Kotlin  (0) 2022.07.25
[Kotlin] 코틀린에서의 변수 사용법  (2) 2022.07.07
코틀린으로 레이아웃 연결하기 (뷰 바인딩)  (0) 2022.07.04
안드로이드 컴파일 (JVM, DVM)  (0) 2022.07.04
    'Android' 카테고리의 다른 글
    • Android BottomNavigation Bar Round효과
    • 안드로이드 액티비티간 화면 전환 및 데이터 전달 (Intent) - Kotlin
    • [Kotlin] 코틀린에서의 변수 사용법
    • 코틀린으로 레이아웃 연결하기 (뷰 바인딩)
    팡세영
    팡세영
    Android, CS, PS

    티스토리툴바