Ir al contenido

Más visitados

Visitados recientemente

navigation

Rotary Input on Wear

Some Wear OS devices support rotary input, such as a rotating side button (RSB). When the user turns the button, your app's current view should scroll up or down.

If you are using ScrollView, ListView, HorizontalScrollView, or WearableRecyclerView in your app, then your app's view gets rotary input support by default. If you are using custom views other than those listed, or if you want to manually handle rotary input events, see Adding Custom Rotary Input Scrolling.

Refer to the following related resources:

Focus Best Practices

To respond to rotary input events, your scroll view must be in focus. In most cases, this happens automatically; your scrolling view becomes focused immediately after you create your Activity. However, there are situations where you need to manually handle focus of your app's view, such as:

Adding Custom Rotary Input Scrolling

If your scrollable view doesn't natively support rotary input scrolling, or if you want to do something other than scrolling in response to rotary input events (zoom in/out, turn dials, etc.), you can use the RotaryEncoder methods in the Wearable Support Library.

The following code snippet shows how to use RotaryEncoder to add custom scrolling in your app's view:

myView.setOnGenericMotionListener(new View.OnGenericMotionListener() {
    @Override
    public boolean onGenericMotion(View v, MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_SCROLL && RotaryEncoder.isFromRotaryEncoder(ev)) {
            // Don't forget the negation here
            float delta = -RotaryEncoder.getRotaryAxisValue(ev) * RotaryEncoder.getScaledScrollFactor(
            getContext());

            // Swap these axes if you want to do horizontal scrolling instead
            scrollBy(0, Math.round(delta));

            return true;
        }

        return false;
    }
});

Testing Rotary Input Button on the Emulator

You can use the Android Emulator to simulate rotary input scrolling on a Wear device. Launch your Wear app on the emulator when you run your project, or drag an APK file onto the emulator to install it.

To test the rotary input on the emulator:

  1. From the SDK manager, use the SDK tools tab to get Android Emulator 26.0.3 or higher.
  2. Create an AVD (Android Virtual Device) with API 25.

    In Studio, select Tools>Android>AVD Manager. Create a new Wear device with API 25.

  3. Run the emulator from the Android Studio.
  4. Try rotary input scrolling.

    Click the overflow button (three dots at the bottom of the emulator toolbar). Click the Rotary input tab in the new window to open the rotary input interface.

The following video shows rotary input in the emulator:

Focus Behavior Tips

Utilizamos cookies para registrar tus preferencias de idioma y visualización de este sitio web.

Recibe novedades y consejos para desarrolladores de Android que te ayudarán a alcanzar el éxito en Google Play.

* Campos obligatorios

¡Ya está!

Seguir a Google Developers en WeChat

¿Quieres navegar por el sitio web en ?

Has solicitado que la página aparezca en , pero tu idioma preferido en este sitio web es el .

¿Quieres cambiar tu preferencia de idioma y navegar por este sitio web en ? Si prefieres dejarlo para más tarde, usa el menú de idioma que se encuentra en la parte inferior de cada página web.

Para esta clase se necesita un nivel de API o superior

La documentación está oculta porque el nivel de API que has seleccionado para ella es . Cambia el nivel de API de la documentación en el selector situado encima del menú de navegación de la izquierda.

Para obtener más información sobre cómo especificar el nivel de API que requiere tu aplicación, lee el artículo Supporting Different Platform Versions (Compatibilidad con diferentes versiones de la plataforma).

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)