240812 android TIL

김정혁·2024년 8월 11일

Android RecyclerView란?

긴 리스트나 그리드 형태의 데이터를 효율적으로 표시하는 UI 컴포넌트, 기존 ListView GridView보다 성능과 유연성이 향상되었다.

어떻게 향상되었냐?

  • 효율적인 데이터 표시
    • 화면에 보이는 항목만 유지하고, 보이지 않는 항목은 재활용하여 메모리 사용을 최적화한다.
  • ViewHolder 패턴
    • 항목의 뷰를 캐시하여 재사용할 수 있도록 도와준다.
  • 어댑터와 레이아웃 관리자
    • Adapter: 데이터와 RecyclerView 항목 뷰를 연결하는 역할
    • LayoutManager: 항목의 배치를 결정하는 것
    • Item: 항목 사이의 간격, 테두리 등을 추가할 수 있다.
    • 아이템 터치 및 스와이프: 다양한 사용자 상호작용을 지원한다.

ContstraintLayout의 속성을 이해하기

layout_constraintStart_toEndof 가 이해가 안되었지만 이제는 이해할 수 있게 되었다.

아래와 같은 xml 레이아웃 코드가 있다고 가정한다.

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView 1"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView 2"
        app:layout_constraintStart_toEndOf="@id/textView1"
        app:layout_constraintTop_toTopOf="parent"/>
        
</androidx.constraintlayout.widget.ConstraintLayout>

여기서 2번째 TextView에 layout_constraintStart_toEndOf 를 이해해보자면

2번째 텍스트 뷰의 시작은
-> textView1의 끝으로 부터 시작된다.

라는 뜻이다.

정말 가독성을 위한 attr로 볼 수 있다.

?attr의 의미

<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>

이런 xml이 있다고하면
?attr 은 무엇일까?

현재 theme에서 정의된 colorPrimaryVariant라는 "속성"을 가져오는 것이다.

보통 ?attr/속성명 형태로 쓰인다.

@와 ?의 차이

@

  • 리소스 ID를 참조할떄 사용

?

  • "현재" 테마나 스타일에서 정의된 속성 값을 참조할 때 사용
profile
ai가 씁니다

0개의 댓글