Android LayoutInflater

2023. 12. 26. 17:10·Android

제가 안드로이드를 처음 시작했을 때는 용어를 이해하는게 제일 힘들었습니다. Context, Activity, Intent, Coroutine 등등... 처음엔 저도 뭐가 뭔지도 모르고 그냥 막 했던 기억이 나네요... 

 

곧 있을 면접을 준비하면서 안드로이드의 기본적인 요소를 하나 하나 다 뜯어보고 있습니다. 그러면서 느낀게 제가 처음엔 이해 못했던 용어들이 이제는 다 이해가 되는겁니다. 그 동안 나 열심히 했구나 ㅠㅠ 내가 한게 틀린게 아니었어  잘했어😭 😭 😭 😭

 

심지어 면접 보는 회사 본사가 판교에 위치했습니다. 판교라니... 판교라니... 제 평생의 꿈이 판교에 있는 회사에서 일하는 건데 지금 제 실력으론 면접을 보는거 자체가 너무 영광인지라 가슴이 두근 거립니다 🤗🤗

 

합격하면 평생 꿈을 이루는거라 너무 좋겠지만 이 면접 자체로도 저에게 너무 큰 경험일거 같아서 제 모든걸 쏟아내려 합니다 🔥🔥🔥🔥 퐈이팅...!!🔥🔥🔥🔥

 

서론이 길었네요 이번장은 Fragment Life Cycle에 대해 공부하다 onCreateView() 함수의 파라미터 중 LayoutInflater 란 파라미터가 있어서 이게 뭐지 ? 해서 글을 작성하게 됐습니다. 

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, 
	savedInstanceState: Bundle?): View? { }

 

[안드로이드 공식 문서]

 

LayoutInflater  |  Android Developers

android.inputmethodservice

developer.android.com

LayoutIflatre란 ? 

안드로이드에서는 화면을 구성하는 XML은 Mark Up Languague에 불과합니다. 따라서 이 XML 파일에 작성된 레이아웃들을 화면에 보여주기 위해서 메모리 상으로 실체화 해주어야 합니다. 이 역할을 해주는 것이 바로 LayoutInflater 입니다. 위 onCreateView() 함수 말고도 Activity의 setContentView(R.id.activity_main) 또한 이런 inflate 역할을 합니다.

 

LayoutInflater 생성 방법

getSystemService

LayoutInflater 객체는 시스템 서비스 객체로 제공되기 때문에 getSystemService 메소드를 이용해 참조할 수 있습니다.

val inflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)

 

getLayoutInflater

Activity에서 직접 LayoutInflater를 가져옵니다.

val inflater: LayoutInflater = getLayoutInflater()

 

LayoutInflater.from(context)

val inflater: LayoutInflater = LayoutInflater.from(context)

 

AsyncLayoutInflater

LayoutInflater는 동기적으로 View를 생성하기 때문에 비동기로 View를 생성하는 방법으로 Main 스레드에서 inflater하는데 시간이 오래 걸릴 때 사용합니다.

val inflater = AsyncLayoutInflater(context)
inflater.inflate(R.layout.my_layout, parent) { view, resId, parent ->
  // parent.addView(view)
}

 

'Android' 카테고리의 다른 글

Android Daum 우편번호 서비스 API With FireBase Hosting  (2) 2024.01.04
Android Base64 Decoding  (0) 2024.01.03
Android Fragment Life Cycle  (1) 2023.12.26
Android Activity Life Cycle  (3) 2023.12.26
Android Platform Architecture  (0) 2023.12.25
'Android' 카테고리의 다른 글
  • Android Daum 우편번호 서비스 API With FireBase Hosting
  • Android Base64 Decoding
  • Android Fragment Life Cycle
  • Android Activity Life Cycle
빨주노초잠만보
빨주노초잠만보
  • 빨주노초잠만보
    과거의 나를 통해 미래의 나를 성장시키자
    빨주노초잠만보
  • 전체
    오늘
    어제
    • 분류 전체보기 (108)
      • 우아한테크코스 (6)
      • TEKHIT ANDROID SCHOOL (4)
      • Android Architecture (8)
      • Android (38)
      • PROJECT (11)
      • KOTLIN (10)
        • 코루틴의 정석 (3)
      • BACK END (12)
      • CS (4)
      • 컨퍼런스 (4)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    DataSource
    Compose Typography
    flow
    STATEFLOW
    2025 우아콘 후기
    value class
    android view lifecylce
    process Context Switching
    sealed class
    코틀린 코루틴의 정석
    Throttle
    DI
    Repository Pattern
    Clean Architecture
    android Room
    callbackflow
    Two pass process
    Room
    view 생명주기
    컴포즈 디자인 시스템
    repository
    orbit
    MVI
    의존성 주입
    android clean architecture
    ThrottleFirst
    안드로이드 디자인 시스템
    thread Context Switching
    retrofit call
    coroutine Context Switching
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
빨주노초잠만보
Android LayoutInflater
상단으로

티스토리툴바