Set Background Image to Relative Layout using Glide in Android

后端 未结 7 558
逝去的感伤
逝去的感伤 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条回答
  •  -上瘾入骨i
    2020-12-24 12:06

    Currently, at version Glide version 4.9.0, you can set a background for Relative Layout as:-

    Glide.with(MainActivity.this)
                        .load(IMAGE_URL)
                        .into(new CustomTarget() {
                            @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
                            @Override
                            public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) {
                                mLinearLayout.setBackground(resource);
                            }
    
                            @Override
                            public void onLoadCleared(@Nullable Drawable placeholder) {
    
                            }
                        });
    

提交回复
热议问题