Search code examples
androidandroid-studiokotlinandroid-developer-api

Display an image using Glide in Android. Can't see anything


I'm trying to display an image using Glide in my ImageView to no avail. I don't get any errors, but I don't see any image either

build.gradle dependencies:

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

my ImageView Layout:

       <ImageView
                    android:id="@+id/profilPicture"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:src="@drawable/medicine">

       </ImageView>

In my MainActivity I try to display the image within a thread

       val thread = Thread {
        try {
            Glide.with(this)
                .load("http://via.placeholder.com/300.png")
                .into(profilPicture)
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    thread.start()

Solution

  • You dont need to create separate thread for loading because Glide does it for you. Just:

    Glide.with(this)
        .load("http://via.placeholder.com/300.png")
        .into(profilPicture)
    

    Will be enough