LoginSignup
2
1

More than 1 year has passed since last update.

【Jetpack Compose】角丸のカードを作る

Posted at

概要

こんな感じの角丸のカードを作ります。
主にジャンルを表示したりするのに使うと思います。
スクリーンショット 2022-09-05 9.50.51.png

コード

まず、角丸にするためにこう書きます。

余白が気になる.kt
        Text(
            modifier = Modifier
                .background(
                    color = Color.Blue,
                    shape = RoundedCornerShape(50)
                ),
            text = "カレー", fontSize = 20.sp, color = Color.White
        )

この状態で表示されるのがこういうカードです。
スクリーンショット 2022-09-05 9.56.55.png
詰まった感じで、綺麗なレイアウトになっていないことがわかると思います。
そのため、paddingで余白を調整します。

余白を調整.kt
        Text(
            modifier = Modifier
                .background(
                    color = Color.Blue,
                    shape = RoundedCornerShape(50)
                )
                .padding(top = 5.dp, start = 20.dp, end = 20.dp, bottom = 5.dp),
            text = "カレー", fontSize = 20.sp, color = Color.White
        )

これで最初に載せた通りのレイアウトにすることができました。

2
1
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
2
1