안드로이드 Glide 사용법 + 고급 심화편


✨ 개요

안드로이드에서 이미지 로딩은 앱 성능과 사용자 경험에 직접적인 영향을 미칩니다.
그중 가장 많이 쓰이는 이미지 라이브러리인 Glide는 빠른 속도, 강력한 캐싱, 다양한 커스터마이징 기능을 제공합니다.

이 포스팅에서는 Glide의 기본 사용법부터 실무 고급 기능까지 단계별로 정리해 드립니다.


1. Glide란?


2. Gradle 설정

dependencies {
    implementation("com.github.bumptech.glide:glide:4.16.0")
    kapt("com.github.bumptech.glide:compiler:4.16.0")
}

3. 기본 사용법

Glide.with(context)
    .load(url)
    .placeholder(R.drawable.loading)
    .error(R.drawable.error)
    .into(imageView)
/*
.load(R.drawable.image)       // 리소스
.load(File("/path/image.jpg")) // 파일
.load(Uri.parse(...))         // Uri
 */

4. 실무에서 많이 쓰는 옵션들

.override(300, 300) // 픽셀 단위 리사이즈
.centerCrop()       // 꽉 차게 자름
    .fitCenter()        // 이미지 전체 보이게
    .circleCrop()       // 동그란 썸네일
.diskCacheStrategy(DiskCacheStrategy.ALL) // 원본+리사이즈 이미지 캐시
    .skipMemoryCache(true) // 메모리 캐시 무시

5. 고급 사용법

Glide.with(context)
    .asBitmap()
    .load(url)
    .into(object : CustomTarget<Bitmap>() {
        override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
            imageView.setImageBitmap(resource)
        }

        override fun onLoadCleared(placeholder: Drawable?) {}
    })
Glide.with(context)
    .load(highQualityUrl)
    .thumbnail(0.1f) // 저해상도 빠른 썸네일 먼저 보여줌
    .into(imageView)
Glide.with(context)
    .asGif()
    .load("https://example.com/animated.gif")
    .into(imageView)
@GlideModule
class MyAppGlideModule : AppGlideModule() {
    override fun applyOptions(context: Context, builder: GlideBuilder) {
        builder.setDefaultRequestOptions(
            RequestOptions()
                .format(DecodeFormat.PREFER_RGB_565) // 메모리 절약
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
        )
    }
}

6. 자주 사용하는 조합

조합 설명
Glide + RecyclerView 썸네일 리스트, 프로필 목록 등
Glide + ViewPager2 배너 슬라이더
Glide + Shimmer 로딩 중 효과와 함께 사용
Glide + Coroutines bitmap 처리 후 imageView에 직접 할당

7. 결론



Related Posts