[TIL]Android Material Component

mandoofu·2024년 9월 6일

안드로이드

목록 보기
5/20
post-thumbnail

Material Design

  • View(Compat 이 들어간 뷰만)에 elevation(shadow) 적용

    • 3차원에 배치되며 빛에 의한 그림자 효과
    • android:elevation(dp,View의 깊이 값)이 추가
    • CardView를 사용하여 하위 버전에서도 효과를 낼 수 있음
    • View에 elevation속성을 적용하려면 부모의 padding이나 자식의 margin속성으로 공간을 주고 Background Color 설정을 한다(부모와 자식 뷰가 같은 color이면 그림자 생성x
  • Context

    • 추상클래스이며 안드로이드 앱 환경에서 Global한 Environment에 접근하기 위한 통로(interface)
    • ActivityManagerService 클래스에서 앱 당 [Key , Value]을 부여하여 앱들을 관리하는데 여기서 Key에 해당하는 부분이 앱에서 사용하는 Context 객체가 됨
  • Context의 종류

    • Application Context
      • Singleton Instance이며 안드로이드 앱 하나에 한 객체만 존재
        • GUI관련 작업에선 사용 x(Toast만 가능)
        • 앱이 종료될 때 까지 한 개의 객체만 사용
    • Activity Context
      • Activity Lifecycle에 맞춰진 Context객체를 의미
      • 해당 Activity가 소멸 될 때 해당 context도 같이 소멸됨
  • CardView

    • Content를 Card에배치하기 위해 사용 elevation값이 지정되어 그림자 효과가 나타나고, corner radius를 지정해 모서리를 둥글게 표현 가능
    • 대표 속성
      • app:cardCornerRadius
      • app:cardBackgroundColor
      • app:cardElevation
      • app:cardMaxElevation
      • app:card*

Fragment

  • 반드시 Activity(Owner) 내부에서 동작
    • 하나의 액티비티에 다양한 화면을 동적으로 구현 가능
    • add, replace, remove, hide등
    • Fragment는 View면서 Layout 역할을 수행
  • Activity Lifecycle에 Fragment Lifecycle은 종속적
  • SAA(Single Activity Architecture)
    • 앱 개발 시 하나의 액티비티에 많은 Fragment를 설계하여 Navigation Graph를 이루며 동작하는 앱
  • Fragment 객체와 Fragment View는 다르게 동작!

-Fragment Lifecycle

  • tools:listitem = @layout/member_list_item

  • RecyclerView Item Decoration

    • item view 위에 추가적인 그리기 작업을 위해 사용
      • DividerItemDecoration
        • 단순선의 명시 or XML을 이용해 확장
      • RecyclerView.ItemDecoration
        • onDrawOver
          • ItemView가 그려진 후에 랜더링(ItemView above)
        • onDraw
          • itemView가 그려지기 전에 랜더링(ItemView Below)
        • getItemOffset
          • itemView와 left/right/bottom/top offset
  • Multi Item

    • 각 아이템의 종류가 다양할 때
    • override fun getItemViewType(positionL Int):Int
  • DiffUtil

    • 두 lists(oldList, newList)차이를 계산해서 변경된 부분만 적용
  • ListAdapter

    • RecyclerView Items CRUD(Diff)를 Background로 처리
    • ListAdapter 는 RecyclerView.Adapter& AsyncListDiffer를 구현한 클래스
      • DiffUtil.ItemCallback을 구현한 객체만 넘겨주면 됨
      • getCurrentList() : 현재 List(old list)
      • submitList(newList: List) : newList로 교체
      • onCurrentListChanged(oldList, newList)

0개의 댓글