I am building an Android App which needs to create several vertical sliders in the same page for music equalizer adjustment, but I can only find horizontal sliders from the official material design documents.
I try to implement default slider from official documents and rotate it with modifier and it works, but the problem is that I am not able to adjust the height now using Modifier
.
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Row(modifier =
Modifier
.fillMaxWidth()
.fillMaxHeight(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
slider()
slider()
slider()
slider()
slider()
slider()
slider()
}
}
}
}
@Composable
fun slider() : Int
{
var sliderPosition by remember { mutableStateOf(0f) }
Slider(
modifier = Modifier
.width(50.dp)
.height(120.dp)
.background(color = Color.Red)
.wrapContentSize()
.rotate(270F)
.padding(start = 0.5.dp),
value = sliderPosition,
valueRange = 1f..10f,
onValueChange = {sliderPosition = it}
)
return sliderPosition.roundToInt()
}