Я пытаюсь реализовать функцию чата в моем приложении. Я имею дело с элементами, которые выдвигаются вверх, когда называется клавиатура. Прямо сейчас то, что, кажется, работает наиболее близко к тому, что я хочу, так это настройка
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
Как прокрутить ленивый столбец, когда называется мягкая клавиатура? ⇐ Android
Форум для тех, кто программирует под Android
-
Anonymous
1740012160
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)
}
}
})
}
}'''
Подробнее здесь: [url]https://stackoverflow.com/questions/79453091/how-to-scroll-lazy-column-when-soft-keyboard-is-called[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия