在安卓中使用 Glide 显示图像。什么也看不见



我试图在ImageView中使用Glide显示图像,但没有成功。我没有任何错误,但我也没有看到任何图像

build.gradle依赖项:

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

我的ImageView布局:

<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>

在我的MainActivity中,我尝试在线程中显示图像

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

Glide不是必需的线程。它使用ui线程异步方式。还可以检查您的图像大小和互联网连接。

Glide.with(this).load(url).into(view);

您不需要为加载创建单独的thread,因为Glide会为您创建。只是:

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

就足够了

最新更新