picasso - 如何使用 picasso 库从 url 设置 drawableleft 图像?
问题描述
我需要drawableLeft
从 url 加载图像。这可能吗?
<TextView
android:id="@+id/txt_check_opportunity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="0dp"
android:drawableLeft="@drawable/ic_star_yellow_24dp"
android:layout_toRightOf="@+id/checkbox_opportunity"
android:text="@string/opportunity"
android:textSize="@dimen/text_large_size"
android:textStyle="bold" />
解决方案
您需要创建一个 Picasso Target
,将图像从 URL 加载到目标中,并使用来自Picasso Target 的回调调用setCompoundDrawablesWithIntrinsicBounds
TextView 。Bitmap
onBitmapLoaded
您还需要记住,毕加索目标被弱引用,因此您需要小心并保持对目标的强引用。
我已经实现了一个名为PicassoTargetableTextView的小部件,它可以完成所有这些工作。您可以PicassoTargetableTextView.load(left, top, right, bottom)
在运行时使用 将可绘制对象加载到 TextView 中。
推荐阅读
- kubernetes - GCP K8s (kubectl) 错误消息(需要“container.leases.get”权限)
- angular - Primeng FilterUtils 每个组件都是唯一的?
- angular - 如何在 Angular 8 组件中声明枚举在 Angular 8 中声明枚举时出现错误
- javascript - Vue.js 不会告诉我错误的行号
- php - jVectormap从数据库添加标记只添加一个标记
- php - Laravel 开发服务器关闭
- javascript - 是否可以将 Javascript 和 erb 交织在一起?
- javascript - 将 Nodejs 与已经制作的 HTML/CSS 一起使用
- mysql - 选择在哪里为空
- dataset - 如何为 Mask RCNN 创建自己的数据集?