App/Android
Android Glide Library사용법
selfstarter
2020. 7. 31. 17:51
- build.gradle 에서 dependencies
dependencies {
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
}
2. xml에 imageView 추가
<ImageView
android:id="@+id/img"
android:layout_width="200dp"
android:layout_height="200dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="50dp"
/>
3. Glide 사용. load에 image url이나 local image path를 넣고 error에는 error 일 때 img url을 넣는다. into함수 안에는 image를 넣을 ImageView 객체를 param으로 넘겨준다
val img : ImageView = findViewById(R.id.img);
Glide.with(this).load("https://cdn.pixabay.com/photo/2017/01/13/01/22/ok-1976099_960_720.png").error(R.drawable.ic_launcher_background).into(img)