简体   繁体   English

如何在android中使用Glide加载静态图像

[英]How to load static image using Glide in android

Im using glide to presenting a banner in my application.我使用 glide 在我的应用程序中展示横幅。 Although it worked on URL string, but I want it to use static images instead.虽然它适用于 URL 字符串,但我希望它使用静态图像。

I have a image test.jpg in /res/drawable .我在/res/drawable有一个图像test.jpg I tried replace the url string with /res/drawable/test.jpg but it wont work.我尝试用/res/drawable/test.jpg替换 url 字符串,但它不起作用。

Here is the code:这是代码:

 Glide.with(viewHolder.itemView)
                        .load("https://laz-img-cdn.alicdn.com/images/ims-web/TB1pHADjBr0gK0jSZFnXXbRRXXa.jpg_1200x1200.jpg")
                        .fitCenter()
                        .into(viewHolder.imageViewBackground);

I prefer using Coil Library because its new and simple to use.我更喜欢使用线圈库,因为它新颖且易于使用。 for you issue use this code对于您的问题,请使用此代码

Glide.with(viewHolder.itemView)
        .load(R.drawable.test)
        .into(viewHolder.imageViewBackground)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM