Compose

사진첩 앱 리스트

----___<<<<< 2023. 5. 13. 18:54

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
DefaultTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
PhotoGallery()
}
}
}
}
}
@Composable
fun PhotoGallery() {
val photos = listOf(
"https://tistory1.daumcdn.net/tistory/3101186/attach/639b0d9d365a4ecf832ea1d7d6735808",
"https://tistory1.daumcdn.net/tistory/3101186/attach/639b0d9d365a4ecf832ea1d7d6735808",
"https://tistory1.daumcdn.net/tistory/3101186/attach/639b0d9d365a4ecf832ea1d7d6735808",
"https://tistory1.daumcdn.net/tistory/3101186/attach/639b0d9d365a4ecf832ea1d7d6735808",
"https://tistory1.daumcdn.net/tistory/3101186/attach/639b0d9d365a4ecf832ea1d7d6735808",
"https://tistory1.daumcdn.net/tistory/3101186/attach/639b0d9d365a4ecf832ea1d7d6735808",
"https://tistory1.daumcdn.net/tistory/3101186/attach/639b0d9d365a4ecf832ea1d7d6735808",
"https://tistory1.daumcdn.net/tistory/3101186/attach/639b0d9d365a4ecf832ea1d7d6735808",
"https://tistory1.daumcdn.net/tistory/3101186/attach/639b0d9d365a4ecf832ea1d7d6735808",
)
val listState = rememberLazyGridState()
LazyVerticalGrid(
columns = GridCells.Fixed(3),
modifier = Modifier.fillMaxSize(),
state = listState
) {
items(photos.size) { index ->
Image(
painter = // 옵션: 이미지 로딩 중에 보여줄 리소스 설정
rememberAsyncImagePainter(ImageRequest.Builder
// 옵션: 에러 발생 시 보여줄 리소스 설정
(LocalContext.current).data(data = photos[index])
.apply<ImageRequest.Builder>(block = fun ImageRequest.Builder.() {
// 옵션: 이미지 로딩 중에 보여줄 리소스 설정
placeholder(R.drawable.ic_launcher_background)
// 옵션: 에러 발생 시 보여줄 리소스 설정
error(R.drawable.ic_launcher_foreground)
}).build()
),
contentDescription = null,
modifier = Modifier
.aspectRatio(1f)
.padding(4.dp),
contentScale = ContentScale.Crop
)
}
}
}
@Composable
fun Greeting( modifier: Modifier = Modifier) {
Text(
text = "Hello!",
modifier = modifier
)
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
DefaultTheme {
PhotoGallery()
}
}
view raw MainActivity.kt hosted with ❤ by GitHub

 

'Compose' 카테고리의 다른 글

coil + navigation  (0) 2023.05.15
coil  (0) 2023.05.13
Box  (0) 2023.05.13
LazyVerticalGrid + Navigation  (0) 2023.05.11
LazyVerticalGrid  (0) 2023.05.11