Wear에서 전체 화면 활동 종료

왼쪽에서 오른쪽으로 스와이프하여 Wear OS 활동을 종료할 수 있습니다. 앱에 가로 스크롤이 있는 경우 사용자가 가장자리로 이동하여 종료합니다. 왼쪽에서 오른쪽으로 스와이프하면 됩니다. 전원 버튼을 눌러도 시계 화면으로 돌아갑니다.

스와이프하여 닫기 동작

현재 화면을 닫으려면 사용자는 왼쪽에서 오른쪽으로 스와이프합니다. 따라서 다음을 사용하는 것이 좋습니다.

  • 세로 레이아웃
  • 콘텐츠 컨테이너

또한 앱에 가로 스와이프 동작

활동 닫기

활동은 스와이프하여 닫기를 자동으로 지원합니다. 활동 스와이프 왼쪽에서 오른쪽으로 이동하면 활동이 닫히고 앱이 아래로 탐색 백 스택

프래그먼트 닫기

프래그먼트에서 스와이프하여 닫기를 지원하려면 프래그먼트가 포함된 뷰는 <ph type="x-smartling-placeholder"></ph> SwipeDismissFrameLayout 클래스. 이를 고려하세요 프래그먼트를 사용할지 결정할 때 선택해야 합니다 사용 SwipeDismissFrameLayout 클래스를 사용합니다.

Kotlin

class SwipeDismissFragment : Fragment() {
    private val callback = object : SwipeDismissFrameLayout.Callback() {
        override fun onSwipeStarted(layout: SwipeDismissFrameLayout) {
            // Optional
        }

        override fun onSwipeCanceled(layout: SwipeDismissFrameLayout) {
            // Optional
        }

        override fun onDismissed(layout: SwipeDismissFrameLayout) {
            // Code here for custom behavior, such as going up the
            // back stack and destroying the fragment but staying in the app.
        }
    }

    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
    ): View =
            SwipeDismissFrameLayout(activity).apply {

                // If the fragment should fill the screen (optional), then in the layout file,
                // in the androidx.wear.widget.SwipeDismissFrameLayout element,
                // set the android:layout_width and android:layout_height attributes
                // to "match_parent".

                inflater.inflate(
                        R.layout.swipe_dismiss_frame_layout,
                        this,
                        false
                ).also { inflatedView ->
                    addView(inflatedView)
                }
                addCallback(callback)
            }
}

자바

public class SwipeDismissFragment extends Fragment {
  private final Callback callback =
    new Callback() {
      @Override
        public void onSwipeStart() {
          // Optional
        }

        @Override
        public void onSwipeCancelled() {
          // Optional
        }

        @Override
        public void onDismissed(SwipeDismissFrameLayout layout) {
          // Code here for custom behavior, such as going up the
          // back stack and destroying the fragment but staying in the app.
        }
      };

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    SwipeDismissFrameLayout swipeLayout = new SwipeDismissFrameLayout(getActivity());

    // If the fragment should fill the screen (optional), then in the layout file,
    // in the androidx.wear.widget.SwipeDismissFrameLayout element,
    // set the android:layout_width and android:layout_height attributes
    // to "match_parent".

    View inflatedView = inflater.inflate(R.layout.swipe_dismiss_frame_layout, swipeLayout, false);
    swipeLayout.addView(inflatedView);
    swipeLayout.addCallback(callback);

    return swipeLayout;
    }
}

참고: 활동 내에서 프래그먼트를 사용할 때는 FragmentManager.add 가 아닌 FragmentManager.replace 스와이프하여 닫기 동작을 지원할 수 있습니다. 이렇게 하면 이전 프래그먼트가 최상위 프래그먼트 아래에 렌더링되고 삭제되었습니다.

가로 스크롤 가능 뷰

경우에 따라(예: 화면 이동을 지원하는 지도가 포함된 보기에서) 사용자 인터페이스는 가로 스와이프를 방지할 수 없습니다. 이 다음과 같은 두 가지 선택사항이 있습니다.

  • 백 스택이 짧으면 사용자는 앱을 닫고 워치 페이스 홈 화면으로 이동합니다.
  • 사용자가 백 스택으로 이동하도록 하려면 뷰를 래핑하면 됩니다. 에지를 지원하는 SwipeDismissFrameLayout 객체에서 설정 스와이프 뷰 또는 하위 요소가 반환되면 가장자리 스와이프가 사용 설정됩니다. true부터 <ph type="x-smartling-placeholder"></ph> canScrollHorizontally() 호출 가장자리 스와이프를 사용하면 화면의 왼쪽 10% 지점에서 스와이프하여 보기를 닫을 수 있습니다. 볼 수 있습니다.

다음 예는 뷰를 래핑하는 방법을 보여줍니다. SwipeDismissFrameLayout 객체:

<androidx.wear.widget.SwipeDismissFrameLayout
    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 me to dismiss me." />
</androidx.wear.widget.SwipeDismissFrameLayout>

Kotlin

activity?.findViewById<SwipeDismissFrameLayout>(R.id.swipe_dismiss_root)?.apply {
    addCallback(object : SwipeDismissFrameLayout.Callback() {

        override fun onDismissed(layout: SwipeDismissFrameLayout) {
            layout.visibility = View.GONE
        }
    })
}

자바

SwipeDismissFrameLayout testLayout =
    (SwipeDismissFrameLayout) activity.findViewById(R.id.swipe_dismiss_root);
testLayout.addCallback(new SwipeDismissFrameLayout.Callback() {
    @Override
    public void onDismissed(SwipeDismissFrameLayout layout) {
        layout.setVisibility(View.GONE);
    }
  }
);

권장되지 않음: 스와이프하여 닫기 사용 중지

일반적으로 사용자가 스와이프하여 닫기 기능을 사용 중지하지 않는 것이 좋습니다. 스와이프로 모든 화면을 닫을 것으로 예상합니다. 예외적인 경우, 기본 테마를 확장하여 <ph type="x-smartling-placeholder"></ph>에 스타일 리소스 android:windowSwipeToDismiss 속성을 설정하세요. 아래의 코드 샘플과 같이 false로 변경합니다.

<resources>
  <style name="AppTheme" parent="@android:style/Theme.DeviceDefault">
    <item name="android:windowSwipeToDismiss">false</item>
  </style>
</resources>

그런 다음 사용자에게 앱의 첫 사용에 대해 알릴 수 있습니다. 전원 버튼을 눌러 앱을 종료할 수 있습니다.

전원 버튼으로 닫기

기기의 전원 버튼을 누르면 전원 키가 전송됩니다. 이벤트를 처리합니다. 따라서 전원 버튼을 뒤로 버튼이나 일반적인 탐색에 사용할 수 있습니다.

전원 버튼을 누르면 시계 화면 홈 화면으로 돌아갑니다. 다음과 같은 두 가지 예외가 있습니다.

  • 사용자가 필기 입력과 같은 입력 방식 편집기 (IME)를 사용하는 경우 인식 화면, 버튼 누르기 IME를 닫고 사용자를 앱으로 돌아옵니다.
  • 사용자가 시계 화면을 보고 있는 경우 하드웨어 버튼 누르기 앱 런처가 열립니다.

참고: 전원 버튼을 누르면 Activity 클래스의 isFinishing() 메서드가 하는 일 true를 반환하지 않으며 키 이벤트를 가로챌 수 없습니다.

자세한 내용은 탐색.