English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Example of Loading Background Image into RelativeLayout Using Glide in Android

Introduction

Glide is a recommended image loading library by Google, which supports loading images from URLs, Android resources, files, and Uris. It also supports loading GIF images and various bitmap processing before image display (such as rounded corners, circular images, Gaussian blur, rotation, grayscale, etc.), caching, request priority handling, animation, thumbnail handling, and custom image size, etc. It is very powerful indeed.

Generally, we use Glide to load images onto ImageView, but how do we load them onto the background of a RelativeLayout?

RelativeLayout is a powerful tool for designing user interfaces because it eliminates nested view groups and keeps our layout flat, which can improve runtime performance. Without further ado, let's take a look at the code together!

Example Code

Glide.with(CommodityActivity.this) 
  .load("the URL you need to load or other parameters") 
  .asBitmap() 
  .into(new SimpleTarget<Bitmap>(180,180) {<span style="white-space:pre"> </span>//set width and height 
   @Override 
   public void onResourceReady(Bitmap resource, GlideAnimation<63; super Bitmap> glideAnimation) {}} 
   Drawable drawable = new BitmapDrawable(resource); 
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 
    rlVenueBg.setBackground(drawable);<span style="white-space:pre"> </span>//Set background 
    }; 
    }; 
   ); 

Glide4.4The usage is as follows:

view is the control we want to load

SimpleTarget<Drawable> simpleTarget = new SimpleTarget<Drawable>() { 
 @Override 
 public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) { 
 view.setBackground(resource); 
 }; 
}; 
Glide.with(this).load(url).into(simpleTarget); 

Summary

That's all for this article. I hope the content of this article has certain reference value for everyone's learning or work. If you have any questions, you can leave a message for communication. Thank you for your support of the Yelling Tutorial.

Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been edited by humans, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to notice#w3Please send an email to codebox.com (replace # with @ when sending an email) to report any violations, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.

You May Also Like