Bha*_*mar 4 android textfield android-jetpack-compose android-jetpack-compose-text
我怎样才能使文本字段随着其文本内容而增加高度?我尝试使用类似于下面的代码,但它的高度是固定的,并且不会增长。
Scaffold(
topBar = {
},
content = {
Box(modifier = Modifier.padding(it)) {
Column(){
LazyColumn(modifier = Modifier.fillMaxHeight(0.9)){
// some composable here for UI
}
Row(){
// icon
BasicTextField(
maxLines = 4,
)
// icon
}
}
}
}
)
Run Code Online (Sandbox Code Playgroud)
虽然我似乎已经通过给列赋予 0.9 来固定高度,但我不明白如何不给出固定高度并仍然随内容动态增长文本字段高度?
检查您的限制和体重。
你可以使用类似的东西:
Column() {
LazyColumn(modifier = Modifier.weight(1f)) {
//....some composable here for UI
}
Row(){ /* .... */ }
)
Run Code Online (Sandbox Code Playgroud)
例如:
Row(
Modifier.padding(horizontal = 8.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(Icons.Filled.Add,"")
BasicTextField(
value = text,
onValueChange = { text = it },
modifier = Modifier
.padding(2.dp)
.weight(1f),
maxLines = 4,
){ innerTextField ->
Box(modifier = Modifier
.background(LightGray,shape = RoundedCornerShape(4.dp))
.padding(4.dp),
contentAlignment = Alignment.CenterStart,){
innerTextField()
}
}
Icon(Icons.Filled.Send,"")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2735 次 |
| 最近记录: |