[null,null,["最后更新时间 (UTC):2025-08-23。"],[],[],null,["# Rotary input with Compose\n\nCompose for Wear OS Material version 2.5 3\n\n*** ** * ** ***\n\nRotary input refers to input from pieces of your watch that spin or rotate. On\naverage, users spend only a few seconds interacting with their watch. You\ncan enhance your user experience by using Rotary input to allow your user to\nquickly accomplish various tasks.\n\nThe three main sources of rotary input on most watches include the rotating side\nbutton (RSB), and either a physical bezel or a touch bezel, which is a circular\ntouch zone around the screen. Though expected behavior may vary based on the\ntype of input, be sure to support rotary input for all essential interactions.\n| **Note:** For View based apps refer to [Rotary input](https://google.github.io/horologist/api/compose-layout/com.google.android.horologist.compose.rotaryinput/rotary-with-scroll.html).\n\nScroll\n------\n\nMost users expect apps to support the scroll gesture. As the content scrolls on\nthe screen, give the users visual feedback in response to rotary interactions.\nVisual feedback can include [scrolling indicators](/reference/kotlin/androidx/wear/compose/material3/package-summary#ScrollIndicator(androidx.compose.foundation.lazy.LazyListState,androidx.compose.ui.Modifier,androidx.wear.compose.material3.ScrollIndicatorColors,kotlin.Boolean,androidx.compose.animation.core.AnimationSpec)) for vertical scroll or\n[page indicators](/reference/kotlin/androidx/wear/compose/material3/package-summary#HorizontalPageIndicator(androidx.wear.compose.foundation.pager.PagerState,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color)).\n\n`ScalingLazyColumn`, `TransformingLazyColumn` and `Picker` support the scroll\ngesture by default, as long as you need to place those components inside\n`AppScaffold` and `ScreenScaffold` and pass the list state between `ScreenScaffold`\nand the component, such as a `TransformingLazyColumn`.\n\n`AppScaffold` and `ScreenScaffold` provides the basic layout structure\nfor Wear OS apps and already has a slot for a scroll indicator with a default implementation. To\ncustomize the scrolling progress, create a scroll indicator based on\nthe list state object, as shown in the following code snippet: \n\n```kotlin\nval listState = rememberTransformingLazyColumnState()\nScreenScaffold(\n scrollState = listState,\n scrollIndicator = {\n ScrollIndicator(state = listState)\n }\n) {\n // ...\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/wear/src/main/java/com/example/wear/snippets/m3/rotary/Rotary.kt#L204-L212\n```\n\nYou can configure a snap behavior for `ScalingLazyColumn` by using\n`ScalingLazyColumnDefaults.snapFlingBehavior`, as shown in the following\ncode snippet: \n\n```kotlin\nval listState = rememberScalingLazyListState()\nScreenScaffold(\n scrollState = listState,\n scrollIndicator = {\n ScrollIndicator(state = listState)\n }\n) {\n\n val state = rememberScalingLazyListState()\n ScalingLazyColumn(\n modifier = Modifier.fillMaxWidth(),\n state = state,\n flingBehavior = ScalingLazyColumnDefaults.snapFlingBehavior(state = state)\n ) {\n // Content goes here\n // ...\n }\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/wear/src/main/java/com/example/wear/snippets/m3/rotary/Rotary.kt#L171-L197\n```\n\nCustom actions\n--------------\n\nYou can also create custom actions that respond to rotary input in your app. For\nexample, use rotary input to zoom in and out or to control volume in a media\napp.\n\nIf your component doesn't natively support scrolling events such as volume\ncontrol, you can handle scroll events yourself. \n\n // VolumeScreen.kt\n\n val focusRequester: FocusRequester = remember { FocusRequester() }\n\n Column(\n modifier = Modifier\n .fillMaxSize()\n .onRotaryScrollEvent {\n // handle rotary scroll events\n true\n }\n .focusRequester(focusRequester)\n .focusable(),\n ) { ... }\n\nCreate a custom state managed in view model, and a custom callback that is used\nto process rotary scroll events. \n\n // VolumeViewModel.kt\n\n object VolumeRange(\n public val max: Int = 10\n public val min: Int = 0\n )\n\n val volumeState: MutableStateFlow\u003cInt\u003e = ...\n\n fun onVolumeChangeByScroll(pixels: Float) {\n volumeState.value = when {\n pixels \u003e 0 -\u003e min (volumeState.value + 1, VolumeRange.max)\n pixels \u003c 0 -\u003e max (volumeState.value - 1, VolumeRange.min)\n }\n }\n\nFor the sake of simplicity, the preceding example uses pixel values that, if\nactually used are likely to be overly sensitive.\n\nUse the callback once you receive the events, as shown in the following snippet. \n\n val focusRequester: FocusRequester = remember { FocusRequester() }\n val volumeState by volumeViewModel.volumeState.collectAsState()\n\n Column(\n modifier = Modifier\n .fillMaxSize()\n .onRotaryScrollEvent {\n volumeViewModel\n .onVolumeChangeByScroll(it.verticalScrollPixels)\n true\n }\n .focusRequester(focusRequester)\n .focusable(),\n ) { ... }\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Change focus behavior](/develop/ui/compose/touch-input/focus/change-focus-behavior)\n- [Add keyboard, mouse, trackpad, and stylus support with Jetpack Compose](/codelabs/large-screens/add-keyboard-and-mouse-support-with-compose)\n- [Compose for Wear OS Codelab](/codelabs/compose-for-wear-os)"]]