Glide4 給非ImageView 添加圖片

項目中需要給全屏得layout添加個背景圖,需要使用到Glide4中得 CustomViewTarget,具體用法如下:

ConstraintLayout layout = findViewById(R.id.layout);

CustomViewTarget<ConstraintLayout, Drawable> viewTarget = new CustomViewTarget<ConstraintLayout, Drawable>(layout) {
            @Override
            protected void onResourceCleared(@Nullable Drawable placeholder) {

            }

            @Override
            public void onLoadFailed(@Nullable Drawable errorDrawable) {

            }

            @Override
            public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                layout.setBackground(resource);
            }
        };

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章