본문 바로가기
Android Studio

[Android Studio] 네트워크로 이미지 불러오기 _ Glide

by 처카푸 2024. 6. 11.

네트워크로 이미지 불러오기 _ Glide

 

1. gradle에 glide 설치하기

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

* glide 홈페이지 참고

 

2. 네트워크 권한 설정하기

- app/manifests/AndroidManifest.xml 파일에 작성

<uses-permission android:name="android.permission.INTERNET" />

 

3. 이미지 뷰로 화면 구성 하기

 

4. java 파일에 이미지뷰 연결하고, Glide 사용하여 코드 작성

public class MainActivity extends AppCompatActivity {

    ImageView img1;
    ImageView img2;
    ImageView img3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        img1 = findViewById(R.id.img1);
        img2 = findViewById(R.id.img2);
        img3 = findViewById(R.id.img3);

        Glide.with(MainActivity.this)
                .load("https://block-posting.s3.ap-northeast-2.amazonaws.com/2024-05-30T02_16_10.5632781.jpg")
                .into(img1);
        Glide.with(MainActivity.this)
                .load("https://block-posting.s3.ap-northeast-2.amazonaws.com/2024-05-30T13_19_45.5510251.jpg")
                .into(img2);
        Glide.with(MainActivity.this)
                .load("https://block-posting.s3.ap-northeast-2.amazonaws.com/2024-05-30T16_23_10.4157593.jpg")
                .into(img3);

    }
}

 

 

 


* 그리드 홈페이지

https://github.com/bumptech/glide

 

GitHub - bumptech/glide: An image loading and caching library for Android focused on smooth scrolling

An image loading and caching library for Android focused on smooth scrolling - bumptech/glide

github.com