본문 바로가기

개발 이야기

[Android]Glide로 이미지 불러오기

728x90

Gradle Dependency추가

implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

 

대부분 아시겠지만 Gradle을 변경하면 Sync를 꼭 해줘야 합니다.

모든라이브러리 공통사항이에요. Dependency추가하고 Sync를 해줘야

Glide입력하고 Alt + Enter를 눌렀을 때 Import class를 할 수 있습니다.

 

 

이미지를 담을 뷰 생성

<ImageView
    android:id="@+id/example"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

drawable폴더안에 이미지를 넣어주세요.

이미지파일의 이름에는 대문자가 들어가면 에러가 난답니다.

ImageView example=findViewById(R.id.example);
Glide.with(this)
        .load(R.drawable.mario)
        .into(example);

성공 ~!

with()에는 context가 들어갑니다.

load()에는 이미지 경로

into()에는 이미지를 띄울 뷰입니다.

 

 

추가적으로 

Glide를 쓰는 이유

1. 이미지를 다룰 수 있는 기능이 많습니다. 이미지 크기조절, CropCircle등

2. Url, 상대경로, 절대경로 가리지 않고 띄울수 있음