시차 스크롤은 배경 콘텐츠와 포그라운드 콘텐츠가 서로 다른 속도로 스크롤되는 기법입니다. 이 기법을 구현하여 앱의 UI를 개선하고 사용자가 스크롤할 때 더 역동적인 환경을 만들 수 있습니다.
버전 호환성
이 구현을 사용하려면 프로젝트 minSDK를 API 수준 21 이상으로 설정해야 합니다.
종속 항목
시차 효과 만들기
시차 효과를 얻으려면 스크롤 컴포저블의 스크롤 값 일부를 시차 효과가 필요한 컴포저블에 적용합니다. 다음 스니펫은 중첩된 두 시각적 요소(이미지와 텍스트 블록)를 가져와 서로 다른 속도로 같은 방향으로 스크롤합니다.
@Composable fun ParallaxEffect() { fun Modifier.parallaxLayoutModifier(scrollState: ScrollState, rate: Int) = layout { measurable, constraints -> val placeable = measurable.measure(constraints) val height = if (rate > 0) scrollState.value / rate else scrollState.value layout(placeable.width, placeable.height) { placeable.place(0, height) } } val scrollState = rememberScrollState() Column( modifier = Modifier .fillMaxWidth() .verticalScroll(scrollState), ) { Image( painterResource(id = R.drawable.cupcake), contentDescription = "Android logo", contentScale = ContentScale.Fit, // Reduce scrolling rate by half. modifier = Modifier.parallaxLayoutModifier(scrollState, 2) ) Text( text = stringResource(R.string.detail_placeholder), modifier = Modifier .background(Color.White) .padding(horizontal = 8.dp), ) } }
코드 관련 핵심 사항
- 컴포저블이 스크롤되는 속도를 조정하는 맞춤
layout
수정자를 만듭니다. Image
는Text
보다 느린 속도로 스크롤되므로 두 컴포저블이 서로 다른 속도로 수직으로 변환되면서 시차 효과가 발생합니다.
결과
이 가이드가 포함된 컬렉션
이 가이드는 더 광범위한 Android 개발 목표를 다루는 선별된 빠른 가이드 모음의 일부입니다.
![](https://developer.android.google.cn/static/images/quick-guides/collection-illustration.png?hl=ko)
목록 또는 그리드 표시
목록과 그리드를 사용하면 앱에서 사용자가 쉽게 소비할 수 있는 시각적으로 만족스러운 형식으로 컬렉션을 표시할 수 있습니다.
![](https://developer.android.google.cn/static/images/quick-guides/collection-illustration.png?hl=ko)
이미지 표시
밝고 흥미로운 시각적 요소를 사용하여 Android 앱에 멋진 디자인과 분위기를 부여하는 기법을 알아보세요.
![](https://developer.android.google.cn/static/images/quick-guides/collection-illustration.png?hl=ko)
표시 텍스트
텍스트는 모든 UI의 핵심 요소입니다. 만족도 높은 사용자 환경을 제공하기 위해 앱에서 텍스트를 표시하는 다양한 방법을 알아보세요.
질문이나 의견이 있으신가요?
자주 묻는 질문(FAQ) 페이지로 이동하여 빠른 가이드를 알아보거나 문의하여 의견을 보내주세요.