0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Jetpack Compose】LazyColumnの上部に要素を固定させてスクロールさせる方法

Last updated at Posted at 2024-12-06

やりたいこと

↓の動画の「Look for the book!」のように、上部にTextなどの要素を固定させたままリストをスクロールさせたい

実現方法

以下のようにLazyColumn上にitemを定義して、その中に要素を指定するだけ。

    @Composable
    private fun SampleList() {
        Scaffold(
            topBar = { TopBar() },
        ) { innerPadding ->
            LazyColumn(
                contentPadding = innerPadding,
            ) {
                item { //このitemカッコ内に固定したい要素を指定する
                    Text(
                        "Look for the book!",
                        modifier = Modifier.padding(start = 8.dp, top = 8.dp),
                        color = colorResource(id = R.color.book_orange),
                        fontWeight = FontWeight.Light,
                        fontSize = with(LocalDensity.current) { 23.dp.toSp() }
                    )
                }
                items() { 
                    // リスト表示
                }
            }
        }
    }

余談:ここらへん地味に詰まってたら、このやり方をつよつよの技術者が教えてくれました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?