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?

Composeで下部のみにShadowをつける

Posted at

はじめに

今回はViewの下部にのみshadowを付けるための拡張関数を紹介していきます

本文

基本的にはCardをで囲えば簡単にできますが、そうでないViewに対してなどに使う機会があったので下記をそのまま使ってもらって良しなに調整していただければ使えるものになっています

private fun Modifier.bottomShadow(
    blurRadius: Float,
    color: Color,
): Modifier {
    return this.then(
        drawBehind {
            drawIntoCanvas {
                val paint = Paint()
                val frameworkPaint = paint.asFrameworkPaint()
                frameworkPaint.maskFilter =
                    BlurMaskFilter(
                        blurRadius,
                        BlurMaskFilter.Blur.NORMAL,
                    )
                frameworkPaint.color = color.toArgb()
                it.drawLine(
                    Offset(0f, size.height),
                    Offset(size.width, size.height),
                    paint,
                )
            }
        },
    )
}

さいごに

デフォルトのshadowだとどうしても全体になってしまったのでしょうがなくどうにかできないものかと思い実装してみました
どなたかのお役に立てれば幸いです

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?