Glide
1. build.gradle
dependencies {
...
// glide
implementation 'com.github.bumptech.glide:glide:4.13.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'
}
위의 2줄을 추가해준다.
2. activity_glide.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".image.GlideActivity">
<ImageView
android:id="@+id/img_gif"
android:layout_width="120dp"
android:layout_height="91dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
3. GlideActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.bumptech.glide.Glide;
import com.taek.test.R;
import com.taek.test.databinding.ActivityGlideBinding;
public class GlideActivity extends AppCompatActivity {
private ActivityGlideBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityGlideBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
Glide.with(this)
.load(R.drawable.OOO)
.into(binding.imgGif);
}
}
load 메서드에 gif 파일을 넣어주면 된다.
- gif파일 : res > drawable 디렉터리에 넣어줌
- URL : URL 주소 넣어줌
이미지 URL을 이용하려면 AndroidMenifest.xml 에 INTERNET permission 추가해줘야 한다.
<manifest
...>
<uses-permission android:name="android.permission.INTERNET"/>
<application
...
'앱 개발 > 안드로이드(Java)' 카테고리의 다른 글
RecyclerView 구현 (0) | 2023.03.10 |
---|---|
ListView 구현 (0) | 2023.03.10 |
ViewBinding 적용하기 (0) | 2023.03.10 |
GPS Background service 구현하기 (1) | 2021.10.27 |
glide를 사용하여 GIF 로딩 화면 구현하기 (4) | 2021.08.17 |