android – 使用Glide为AppWidget加载图像

android – 使用Glide为AppWidget加载图像,第1张

概述我正在处理我的第一个应用小部件. 除了一件事外,一切都很好.我无法找到,如何使用Glide将图像加载到RemoteViewsFactroy的getViewAt()方法的 ImageView中.我总是得到错误,因为我要在MainThread中遇到(AppWidgetTarget),但是我无法从RemoteViewsFactory调用新的Handler(Looper.getMainLooper()). 我正在处理我的第一个应用小部件.
除了一件事外,一切都很好.我无法找到,如何使用GlIDe将图像加载到RemoteVIEwsFactroy的getVIEwAt()方法的 ImageVIEw中.我总是得到错误,因为我要在MainThread中遇到(AppWidgetTarget),但是我无法从RemoteVIEwsFactory调用新的Handler(Looper.getMainLooper()).解决方法 GlIDe通过提供 AppWidgetTarget级别为此提供支持.

在onUpdate()中更新窗口小部件时,您创建一个新的AppWidgetTarget,将其传递给RemoteVIEws对象,图像视图的ID和appWidgetID,然后以与应用程序中的imagevIEw几乎相同的方式调用滑动.

appWidgetTarget = new AppWidgetTarget( context,rv,R.ID.custom_vIEw_image,appWidgetIDs );    GlIDe            .with( context.getApplicationContext() ) // safer!            .load( GlIDeExampleActivity.eatFoodyImages[3] )            .asBitmap()            .into( appWidgetTarget );

上面的示例代码取自本wonderful set of glide tutorials.教程涵盖了使用滑行的许多实际方面.

类似地,滑动也提供了NotificationTarget目标类 – 它解决了同样的问题,但是对于通知而不是appWidgets.

总结

以上是内存溢出为你收集整理的android – 使用Glide为AppWidget加载图像全部内容,希望文章能够帮你解决android – 使用Glide为AppWidget加载图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1125919.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存