Glide如何给textview设置背景图片?

How to set the background image for textview with Glide?

如何使用滑动设置文本的背景图片?

file[0] = "mnt/sdcard/sort_icon.png"


SimpleTarget target = new SimpleTarget<Drawable>(){
                    @Override
                    public void onResourceReady(Drawable resource, GlideAnimation<? super Drawable> glideAnimation) {
                        txtView.setBackground(resource);
                    }
                };
                Glide.with(getBaseContext())
                        .load(file[i-4])
                        .into(target);

解法:

试试这个:

在您的 gradle(app) 中添加实现:

dependencies {
    .....
    .....

    def glide = "4.8.0"

    // Glide
    implementation "com.github.bumptech.glide:glide:$glide"
    annotationProcessor "com.github.bumptech.glide:compiler:$glide"
    .....
}

然后,在你的 Activity/Fragment:

File file = new File(file[i-4]);
Uri imageURI = Uri.fromFile(file);

Glide.with(MainActivity.this)
     .load(imageURI)
     .apply(RequestOptions.placeholderOf(R.drawable.ic_launcher))
     .into(new SimpleTarget<Drawable>() {
          @Override
          public void onResourceReady(@NonNull Drawable resource, 
                      @Nullable Transition<? super Drawable> transition) {

                     txtView.setCompoundDrawablesWithIntrinsicBounds(resource, null, null, null);

                }
            });

看看是否有效。