Created
June 12, 2022 20:16
-
-
Save aqua30/54de8136cb56d711bc10c16a72125458 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun ImageParallaxScroll() { | |
val scrollState = rememberScrollState() | |
Column( | |
modifier = Modifier | |
.fillMaxWidth() | |
.verticalScroll(scrollState), | |
) { | |
Box( | |
modifier = Modifier | |
.fillMaxWidth() | |
.height(500.dp) | |
.background(Color.White) | |
.graphicsLayer { | |
alpha = 1f - ((scrollState.value.toFloat() / scrollState.maxValue) * 1.5f) | |
translationY = 0.5f * scrollState.value | |
}, | |
contentAlignment = Alignment.Center | |
) { | |
Image( | |
painterResource(id = R.drawable.ic_tiger), | |
contentDescription = "tiger parallax", | |
contentScale = ContentScale.Crop, | |
modifier = Modifier.fillMaxSize() | |
) | |
} | |
Text( | |
text = stringResource(R.string.dummy_text), | |
modifier = Modifier.background( | |
Color.White | |
), | |
style = TextStyle( | |
fontSize = 24.sp | |
) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment