android jetpack compose - How to keep the scrolled bottom item visible when ime appears? - Stack Overflow

|-|iI'm trying to make a column able to keep visible the bottom item when ime gets displayedI ha

|-|i

I'm trying to make a column able to keep visible the bottom item when ime gets displayed

I have a text field at bottom of screen, and above is the column, filled with random text to make it scroll.

I tried a bit Modifier.imeNestedScroll(), but I struggle, I'm not even sure it would do the job

Here is my code currently, but it's kinda buggy...

ComposeTestTheme {
    Scaffold(modifier = Modifier.fillMaxSize())
    { innerPadding ->
        Column(
            modifier = Modifier
                .padding(innerPadding)
                .consumeWindowInsets(innerPadding)
                .fillMaxSize()
        )
        {
            LazyColumn(
                modifier = Modifier
                    .weight(1f)
                    .fillMaxWidth()
                    .border(2.dp, Color.Red)
                    .imeNestedScroll()
            )
            {
                items(50) { index ->
                    Text(text = "item: $index")
                }
            }
            TextField(
                value = "",
                onValueChange = {},
                modifier = Modifier
                    .fillMaxWidth()
                    .border(2.dp, Color.Black)
                    .imePadding()
            )
        }
    }
}

Could someone help?

|-|i

I'm trying to make a column able to keep visible the bottom item when ime gets displayed

I have a text field at bottom of screen, and above is the column, filled with random text to make it scroll.

I tried a bit Modifier.imeNestedScroll(), but I struggle, I'm not even sure it would do the job

Here is my code currently, but it's kinda buggy...

ComposeTestTheme {
    Scaffold(modifier = Modifier.fillMaxSize())
    { innerPadding ->
        Column(
            modifier = Modifier
                .padding(innerPadding)
                .consumeWindowInsets(innerPadding)
                .fillMaxSize()
        )
        {
            LazyColumn(
                modifier = Modifier
                    .weight(1f)
                    .fillMaxWidth()
                    .border(2.dp, Color.Red)
                    .imeNestedScroll()
            )
            {
                items(50) { index ->
                    Text(text = "item: $index")
                }
            }
            TextField(
                value = "",
                onValueChange = {},
                modifier = Modifier
                    .fillMaxWidth()
                    .border(2.dp, Color.Black)
                    .imePadding()
            )
        }
    }
}

Could someone help?

Share Improve this question asked Jan 17 at 20:13 RaphaelRaphael 455 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Done this way:

Scaffold(modifier = Modifier.fillMaxSize())
{ innerPadding ->
    Column(
        modifier = Modifier
            .padding(innerPadding)
            .consumeWindowInsets(innerPadding)
            .fillMaxSize()
    )
    {
        val list = remember { (1..130).map{ it.toString() }.toList() }
        LazyColumn(
            reverseLayout = true,
            modifier = Modifier
                .fillMaxWidth()
                .weight(1f)
                .border(2.dp, Color.Red)
        )
        {
            items(list.size) { message ->
                Text(text = message.toString())
            }
        }

        TextField(
            value = "",
            onValueChange = { },
            modifier = Modifier
                .imePadding()
                .fillMaxWidth()
                .border(2.dp, Color.Black)
        )
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745346679a4623582.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信