android - How to set the background image for textview with Glide?
问题描述
How do I set background image for text 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);
解决方案
Solution:
Try this:
Add the implementation in your gradle
(app):
dependencies {
.....
.....
def glide = "4.8.0"
// Glide
implementation "com.github.bumptech.glide:glide:$glide"
annotationProcessor "com.github.bumptech.glide:compiler:$glide"
.....
}
Then, in your 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);
}
});
See if it works.
推荐阅读
- jakarta-ee - 实体 JPA Hibernate 错误
- java - 用于从给定 DFA 打印所有接受的字符串(如果无限量则为上限)的算法
- python-3.x - 基于唯一 ID 和绘图图的 Pandas Dataframe 中两列的对角线差异
- javascript - 在 Laravel 中使用 AJAX 编辑字段
- ionic-framework - ios模拟器上的离子3导航问题
- javascript - 使用 chrome 扩展 javascript 将事件同步到谷歌日历
- c# - .NET Core,通过验证将字符串绑定到集合
- c - 分配 10kb 内存并打印地址和内容
- java - 使用 Java 6 的 SpringBoot CRUD api
- c# - Razor Pages 在路由中添加扩展