Set Background Image to Relative Layout using Glide in Android

后端 未结 7 557
逝去的感伤
逝去的感伤 2020-12-24 11:33

How can I do this using Glide? I want to cache image to use it another time also. Thanks in advance.

相关标签:
7条回答
  • 2020-12-24 12:18

    (SimpleTarget class is Deprecated So using CustomTarget class to Load image)

    You can load an image in a RelativeLayout like this. I'm just showing you the hard part which is setting an image to the background.

    For Glide version before 4.X (Without Deprecation)

    Glide.with(this).load(ServiceGenerator.BASE_URL + url).into(new CustomTarget<Drawable>() {
                @Override
                public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                    yourRelativeLayout.setBackground(resource);
                }
    
                @Override
                public void onLoadCleared(@Nullable Drawable placeholder) {
                }
    
            });
    
    0 讨论(0)
提交回复
热议问题