Как прокрутить ленивый столбец, когда называется мягкая клавиатура?Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Как прокрутить ленивый столбец, когда называется мягкая клавиатура?

Сообщение Anonymous »

Я пытаюсь реализовать функцию чата в моем приложении. Я имею дело с элементами, которые выдвигаются вверх, когда называется клавиатура. Прямо сейчас то, что, кажется, работает наиболее близко к тому, что я хочу, так это настройка
android: windowsoftinputmode = "routationnothing"
и добавление накладки IME и вставки для окон, так как я использую каркас.
Однако, однако, Заполнение для коробки чата Lazy Move Move, но не содержимое. Вместо этого я попытался использовать смещение Y, но я не совсем уверен, как получить высоту клавиатуры. < /P>
'' '< /p>
Box(
Modifier
.padding(top = 10.dp)
.fillMaxSize()
.consumeWindowInsets(padding)
.imePadding()
.zIndex(0.5f)
) {

var listState = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()
var textBoxList = remember {
mutableStateListOf(
TextBoxData("This is the first message", "Bot"),
TextBoxData("This is the second message", "User"),
TextBoxData("This is the first message", "Bot"),
TextBoxData("This is the second message", "User"),
TextBoxData("This is the first message", "Bot"),
TextBoxData("This is the second message", "User"),
TextBoxData("This is the first message", "Bot"),
TextBoxData("This is the second message", "User"),
TextBoxData("This is the first message", "Bot"),
TextBoxData("This is the second message", "User"),
TextBoxData("This is the first message", "Bot"),
TextBoxData("This is the second message", "User"),
TextBoxData("This is the first message", "Bot"),
TextBoxData("This is the last message", "User"),

)
}
//lazyColumn for chat
LazyColumn(
Modifier
.fillMaxSize()
.padding(bottom = 50.dp),
state = listState
) {
//For Each, Map
items(textBoxList) { item ->
TextBox(item)
}

}

//Bottom Input Bar
Box(
Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth()
.height(50.dp)
.clip(RoundedCornerShape(20.dp))
.background(Black)
.border(2.dp, White, RoundedCornerShape(20.dp))
) {
Row(
Modifier
.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = FeatherIcons.Mic,
"Microphone Icon",
tint = White,
modifier = Modifier
.fillMaxHeight()
.padding(start = 10.dp)
)

//Text Field Here
var inputText by remember { mutableStateOf("") }
var textFieldScrollState = rememberScrollState(10)
var lineWidth = 255.dp
var textWidth = measureTextWidth(
inputText,
TextStyle(
fontSize = 16.sp,
fontFamily = RalewayRegular
)
)
//Configure the Alignment and Scroll State
TextField(
value = inputText,

onValueChange = {
inputText = it

val currLine = (textWidth / lineWidth).toInt()
coroutineScope.launch {
textFieldScrollState.scrollTo(
//Dont scroll if on first line (Default is 0)
if (currLine == 0) 5 else textFieldScrollState.maxValue - 5
)

Log.i("TextSize",
listState.layoutInfo.viewportEndOffset.toString()
)
}

},

placeholder = {
Text(
"Type Something...",
color = White.copy(0.7f),
fontSize = 16.sp,
lineHeight = 16.sp,
fontFamily = RalewayRegular
)
},

textStyle = TextStyle(
color = White,
fontSize = 16.sp,
fontFamily = RalewayRegular,
textAlign = TextAlign.Start,
),

modifier = Modifier
.width(290.dp)
.fillMaxHeight()
.padding(start = 10.dp)
.verticalScroll(textFieldScrollState),

colors = TextFieldDefaults.colors(
focusedTextColor = White,
unfocusedTextColor = White,
unfocusedContainerColor = Black,
focusedContainerColor = Black
)
)

val regex_space =
Regex("^\\s*\$") // \\s* means unlimited number of empty (\\s)
Icon(imageVector = FeatherIcons.Send,
contentDescription = "Send button",
tint = White,
modifier = Modifier
.fillMaxHeight()
.padding(start = 10.dp)
.clickable {
if (!inputText.matches(regex_space)) {
textBoxList.add(TextBoxData(inputText, "User"))
inputText = ""

//Use Coroutine Scope to Scroll
//LazyColumn needs items(textBoxList) to scroll to the item index
coroutineScope.launch {
listState.scrollToItem(textBoxList.size - 1)
}
}
})
}
}'''


Подробнее здесь: https://stackoverflow.com/questions/794 ... -is-called
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»