728x90
반응형
Glide
- Glide는 이미지 로딩, 디코딩, 캐싱을 손쉽게 처리할 수 있는 Android 이미지 로딩 라이브러리
- GIF, 비디오 썸네일, 로컬/원격 이미지 등 다양한 미디어 포맷을 지원
- Google 공식 지원 라이브러리로 Android의 RecyclerView와 함께 최적화되어 있다.
특징
- 강력한 캐싱: 디스크 및 메모리 캐싱 지원으로 빠른 로딩
- GIF 지원: 정적 이미지뿐만 아니라 GIF 애니메이션 처리 가능
- 비디오 썸네일: 비디오의 특정 프레임을 썸네일로 추출
- RecyclerView 최적화: 스크롤 성능에 최적화된 이미지 처리
- 간단한 API: 코드가 직관적이며 쉽게 배울 수 있음
Glide 기본 사용법
1. Gradle에 Glide 추가
dependencies {
implementation 'com.github.bumptech.glide:glide:4.15.1'
kapt 'com.github.bumptech.glide:compiler:4.15.1'
}
- Kotlin 프로젝트의 경우 kapt 추가가 필요
- Java에서는 annotationProcessor를 사용
2. XML 레이아웃 (activity_main.xml)
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="centerCrop" />
- 이미지 뷰 생성
3. MainActivity (이미지 로딩)
import com.bumptech.glide.Glide
val imageView = findViewById<ImageView>(R.id.imageView)
val imageUrl = "https://via.placeholder.com/300.png"
Glide.with(this)
.load(imageUrl) // 이미지 URL 또는 리소스
.into(imageView) // 이미지를 표시할 ImageView
- with(context) → Glide 인스턴스 초기화
- load() → 이미지 로딩 (URL, 리소스, 파일 등)
- into() → 이미지를 표시할 뷰 지정
Glide의 고급 기능
Placeholder와 Error 이미지 처리
- Placeholder: 이미지 로딩 중 임시로 표시되는 이미지
- Error: 로딩 실패 시 표시되는 이미지
Glide.with(this)
.load("https://invalid-url.com/image.jpg")
.placeholder(R.drawable.placeholder) // 로딩 중 표시
.error(R.drawable.error_image) // 로딩 실패 시 표시
.into(imageView)
https://bumptech.github.io/glide/doc/getting-started.html
Glide v4 : Getting Started
Basic Usage Loading images with Glide is easy and in many cases requires only a single line: Glide.with(fragment) .load(myUrl) .into(imageView); Cancelling loads you no longer need is simple too: Glide.with(fragment).clear(imageView); Although it’s good
bumptech.github.io
728x90
반응형
'안드로이드 학습(Kotlin)' 카테고리의 다른 글
LocationRequest란? (0) | 2025.02.06 |
---|---|
17. Android Animation (Property Animation) (1) | 2025.02.04 |
15. ViewPager의 개념과 구조 (0) | 2025.02.04 |
14. RecyclerView와 Adapter, ViewHolder에 대해 (0) | 2025.02.04 |
13. View 이벤트 (키, 포커스) (0) | 2025.02.04 |