Android NDK开发详解Wear之滑块和分段滑块

Android NDK开发详解Wear之滑块和分段滑块

滑块

InlineSlider 组件可允许用户从一系列值中进行选择。
在这里插入图片描述


fun InlineSlider(
    value: Float,
    onValueChange: (Float) -> Unit,
    steps: Int,
    decreaseIcon:  () -> Unit,
    increaseIcon:  () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    valueRange: ClosedFloatingPointRange<Float> = 0f..(steps + 1).toFloat(),
    segmented: Boolean = steps <= 8,
    colors: InlineSliderColors = InlineSliderDefaults.colors()
): Unit

InlineSlider allows users to make a selection from a range of values. The range of selections is shown as a bar between the minimum and maximum values of the range, from which users may select a single value. InlineSlider is ideal for adjusting settings such as volume or brightness.

Value can be increased and decreased by clicking on the increase and decrease buttons, located accordingly to the start and end of the control. Buttons can have custom icons - decreaseIcon and increaseIcon.

The bar in the middle of control can have separators if segmented flag is set to true. A single step value is calculated as the difference between min and max values of valueRange divided by steps + 1 value.

A continuous non-segmented slider sample:

import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.InlineSlider

var value by remember { mutableStateOf(4.5f) }
InlineSlider(
    value = value,
    onValueChange = { value = it },
    increaseIcon = { Icon(InlineSliderDefaults.Increase, "Increase") },
    decreaseIcon = { Icon(InlineSliderDefaults.Decrease, "Decrease") },
    valueRange = 3f..6f,
    steps = 5,
    segmented = false
)

A segmented slider sample:

import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.wear.compose.material.Icon
import androidx.wear.compose.material.InlineSlider

var value by remember { mutableStateOf(2f) }
InlineSlider(
    value = value,
    onValueChange = { value = it },
    increaseIcon = { Icon(InlineSliderDefaults.Increase, "Increase") },
    decreaseIcon = { Icon(InlineSliderDefaults.Decrease, "Decrease") },
    valueRange = 1f..4f,
    steps = 7,
    segmented = true
)

在这里插入图片描述

使用内嵌滑块从范围中选择一个值,例如设置屏幕亮度或字体大小。使用滑块所做的更改会立即生效,并允许用户在满意之前继续进行调整。如果不希望调整立即生效,请勿使用滑块。

剖析

在这里插入图片描述

A. 进度条
B. 进度轨道
C. 容器
D. 减少图标
E. 增加图标
F. 分隔符

设计建议

在这里插入图片描述

分段滑块
如果值的范围介于 3 和 9 之间,请考虑使用分段滑块。如果值的范围大于 8,则分段将因过小而无法显示。

用法

请参见以下滑块示例。

在这里插入图片描述

步进控件

Stepper 组件可让用户从一系列值中进行选择。
在这里插入图片描述

在这里插入图片描述

使用步进控件提供全屏控制体验,让用户从一系列值中进行选择。

剖析

在这里插入图片描述

A. 调大按钮
B. 标签或条状标签
C. 调小按钮

用法

请查看下方示例,了解如何使用步进控件。
在这里插入图片描述

请查看 GitHub 上的 Horologist 库,该库提供了音量控制屏幕的实现方案。
🔊 Audio and UI
Domain model for Audio related functionality. Volume Control, Output switching. Subscribing to a Flow of changes in audio or output.

horologist-audio
horologist-audio-ui
VolumeScreen

🔐 Auth
Libraries to help developers to build apps following the Sign-In guidelines for Wear OS .

horologist-auth-composables: composable screens for authentication use cases, with no dependency on the auth-data library.
horologist-auth-ui: composable screens for authentication use cases, with integration with the auth-data library
horologist-auth-data: implementation for Wear apps for most of the authentication methods listed in the Authentication on wearables guide.
horologist-auth-data-phone: implementation for Mobile apps for some of the authentication methods provided by the auth-data library.
sample wear: sample wear app to authenticate using different methods.
sample phone: sample phone app to authenticate using different methods.
☰ Tiles
Kotlin coroutines flavoured TileService.

horologist-tiles

Why the name?
The name mirrors the Accompanist name, and is also Watch related.

https://en.wiktionary.org/wiki/horologist

horologist (Noun) Someone who makes or repairs timepieces, watches or clocks.

Contributions
Please contribute! We will gladly review any pull requests submitted. Make sure to read the Contributing page to know what our expectations of contributions are.

License
Copyright 2023 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。

最后更新时间 (UTC):2022-09-07。

  • 23
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五一编程

程序之路有我与你同行

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值