当屏幕旋转Android小工具的ImageButton失去图像 [英] Android widget ImageButton loses image when screen is rotated

查看:144
本文介绍了当屏幕旋转Android小工具的ImageButton失去图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有哪些有默认背景图片几个ImageButtons我家的屏幕上的一个小部件。通过配置活动,我可以在任何ImageButtons的改变形象。的问题是,当屏幕被转动时,上的ImageButton在前看不见的图像,并将其变回默认图像。

I have a widget on my home screen with several ImageButtons which have default background images. Through the configuration activity, I can change the image on any of the ImageButtons. The problem is that when the screen is rotated, the image on the ImageButton disapears and it changes back to the default image.

我不知道为什么发生这种情况或如何解决它。

I don't know why this happens or how to fix it

推荐答案

当屏幕旋转时,整个appwidget使用的是最后一个<重建了href=\"http://developer.android.com/intl/zh-CN/reference/android/widget/RemoteViews.html\">RemoteViews对象,你传递给<一个href=\"http://developer.android.com/intl/zh-CN/reference/android/appwidget/AppWidgetManager.html\">AppWidgetManager.updateAppWidget().因此,它是非常重要的,你每次调用updateAppWidget()所传递的每样东西上设置小部件需要如果它被完全重建,要在窗口更新不只是一两件事情一个RemoteViews对象显示。

When the screen is rotated the entire appwidget is rebuilt using the last RemoteViews object you passed to AppWidgetManager.updateAppWidget(). Thus is it very important that every time you call updateAppWidget() you pass a RemoteViews object that has everything set on it that the widget needs if it were to be completely rebuilt, not just one or two things that you want to update on the widget display.

所以,在你的<一个href=\"http://developer.android.com/intl/zh-CN/reference/android/appwidget/AppWidgetProvider.html\">AppWidgetProvider类,每当你更新你appwidget需要创建一个RemoteViews对象,使用该对象建立全方位为您appwidget视图设置,然后进行一次调用AppWidgetManager.updateAppWidget()当您完成。

So, in your AppWidgetProvider class, whenever you are updating your appwidget you need to create a RemoteViews object, build up all the view settings for your appwidget using that object, and then make one call to AppWidgetManager.updateAppWidget() when you are done.

我的猜测是你正在做这样的事情:

My guess is you are doing something like this:


  • 获取RemoteViews对象

  • 设置新的按钮图像

  • 呼叫updateAppWidget()

  • 获取RemoteViews对象

  • 在按钮设置挂起的意图

  • 呼叫updateAppWidget()

当你需要做这样的事情:

When you need to be doing something like this:


  • 获取RemoteViews对象

  • 设置新的按钮图像

  • 在按钮设置挂起的意图

  • 呼叫updateAppWidget()

这篇关于当屏幕旋转Android小工具的ImageButton失去图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆