提交 d6eb09fe 编写于 作者: H hdx

test_compose_ui_slider_100: 显示 value 值,限制值范围(0-100)

上级 27854744
......@@ -16,18 +16,25 @@ import com.example.jetpackcompose.ui.theme.JetpackComposeTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val min = 0f
val max = 1f
setContent {
JetpackComposeTheme {
// A surface container using the 'background' color from the theme
Row {
var sliderPosition by remember { mutableStateOf(0f) }
var sliderPosition by remember { mutableStateOf(0.5f) }
repeat(4) {
Column(
modifier = Modifier.weight(1f)
) {
for (i in 1..25) {
Slider(value = sliderPosition, modifier = Modifier
.height(25.dp), onValueChange = { sliderPosition = it })
Row(verticalAlignment = Alignment.CenterVertically) {
Text(text = (sliderPosition * 100).toInt().toString(), Modifier.width(30.dp))
Slider(
valueRange = (min..max), value = sliderPosition, modifier = Modifier
.height(25.dp), onValueChange = { sliderPosition = it })
}
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册