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

More than 1 year has passed since last update.

お題は不問!Qiita Engineer Festa 2023で記事投稿!

JetpackCompose無限に点滅するアニメーションの実装方法

Last updated at Posted at 2023-07-09

今回は繰り返すアニメーションについて調べてみました。

点滅のアニメーションをさせたいわけではなく、どちらかと言うと繰り返す方法を探していました。

サンプルコードです

.kt
val infiniteTransition = rememberInfiniteTransition()
val alpha by infiniteTransition.animateFloat(
    initialValue = 0f,
    targetValue = 1f,
    animationSpec = infiniteRepeatable(
        animation = keyframes {
            durationMillis = 500
        },
        repeatMode = RepeatMode.Reverse
    )
)
Surface(
    shape = MaterialTheme.shapes.small
) {
    Spacer(
        modifier = Modifier
            .fillMaxWidth()
            .height(100.dp)
            .background(Color(0xFF666666).copy(alpha = alpha))
    )
}

repeatMode = RepeatMode.Reverseこちらが繰り返す処理の設定です。

アニメーションの方はinitialValue = 0fで透明からtargetValue = 1f表示へと変化します。
durationMillis = 500でアニメーションする時間を設定してます。

作成したアニメーションはbackgroundalphaに設定します。
Videotogif (4).gif

以上です。

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