Wear OS에서 뷰 기반 UI 빌드

Android Jetpack에는 Wear OS UI 라이브러리가 포함되어 있습니다. Wear OS UI 라이브러리에는 다음 클래스가 포함되어 있습니다.

  • CurvedTextView: 뷰에 표현될 수 있는 가장 큰 원의 곡선을 따라 텍스트를 쉽게 작성하기 위한 구성요소입니다.
  • DismissibleFrameLayout: 사용자가 뒤로 버튼을 누르거나 화면을 왼쪽에서 오른쪽으로 스와이프하여 뷰를 닫을 수 있는 레이아웃입니다. Wear OS 사용자는 뒤로 작업을 위해 왼쪽에서 오른쪽으로 스와이프할 것을 기대합니다.
  • WearableRecyclerView: WearableLinearLayoutManager를 사용하여 하위 레이아웃을 업데이트하는 기본 오프셋 로직을 제공하는 뷰입니다.
  • AmbientModeSupport: 대기 모드를 지원하기 위해 AmbientModeSupport.AmbientCallbackProvider 인터페이스와 함께 사용되는 클래스입니다.

전체 목록은 출시 노트를 참고하세요.

Wear OS UI 라이브러리에 종속 항목 추가

앱을 만들려면 Wear OS 전용 프로젝트를 만듭니다. 그런 다음, 앱의 build.gradle 파일에 다음 종속 항목을 추가합니다.

dependencies {
    ...
  // Standard Wear OS libraries
  implementation "androidx.wear:wear:1.2.0"
  // includes support for wearable specific inputs
  implementation "androidx.wear:wear-input:1.1.0"
}

Wear OS UI 라이브러리 패키지에서 클래스 가져오기

Wear OS UI 라이브러리의 클래스를 사용하려면 androidx.wear.widget 패키지에서 클래스를 가져오세요.

레이아웃 파일에서 올바른 요소 이름 사용

레이아웃 파일에서 Wear OS UI 라이브러리에 상응하는 정규화된 이름을 사용합니다.

예를 들어 Wear OS UI 라이브러리의 DismissibleFrameLayout 클래스를 사용하려면 레이아웃 파일에서 다음을 지정하면 됩니다.

<androidx.wear.widget.DismissibleFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/swipe_dismiss_root" >

    <TextView
        android:id="@+id/test_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="Swipe the screen to dismiss me." />
</androidx.wear.widget.DismissibleFrameLayout>