【问题标题】:AppWidgetTarget doesn't work inside RemoteViewsFactory. How to get around this?AppWidgetTarget 在 RemoteViewsFactory 中不起作用。如何解决这个问题?
【发布时间】:2021-08-11 10:16:50
【问题描述】:

没有足够的文档或博客围绕这个主题。

有人能指出我正确的方向吗?在 getView 中试过这个。适用于不属于列表视图项目的图像视图。

                 val articleImage: AppWidgetTarget = object : AppWidgetTarget(appContext, R.id.article_image, views, appWidgetId) {
                    override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                        super.onResourceReady(resource, transition)
                    }
                }

                val options = RequestOptions()
                    .override(62, 62)
                    .placeholder(R.drawable.news_thumbnail)
                    .error(R.drawable.news_thumbnail)

                Glide
                    .with(appContext)
                    .asBitmap()
                    .load("/*URL*/")
                    .apply(options)
                    .into(articleImage)

【问题讨论】:

  • 这已在here 中得到回答,它使用毕加索而不是 Glide。
  • 这是一个不同的解决方案。如果您希望在 RemoteViewsFactory 中加载图像,这是一个很好的解决方法

标签: android android-appwidget appwidgetprovider android-appwidget-list


【解决方案1】:

AppWidgetTarget 似乎直接用于应用小部件布局中的ImageView,如it uses updateAppWidget() to push over the change。它似乎与RemoteViewsFactory 无关,这是您在应用小部件中填充AdapterView 的方式。

【讨论】:

  • 对。看代码是有道理的。是否没有直接或开箱即用的解决方案来实现这一目标? ?
  • @suhas_sm:我在 Glide 目录中没有看到合适的 Target,我不确定它是否可能。我不知道RemoteViewsFactory 的“推送”机制,这样您就可以在图像到达时更新列表中的一行。
  • 另一种解决方案有效。在问题下发表评论。谢谢,马克。
猜你喜欢
  • 2014-01-28
  • 1970-01-01
  • 2011-04-30
  • 2022-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-28
  • 1970-01-01
相关资源
最近更新 更多