Ash*_*ell 9 android widget android-widget android-appwidget
我在AppWidget中更新RemoteView时出现错误.
.. !!! 失败的粘合剂交易!
这是因为对RemoteViews的所有更改都是序列化的(例如setInt和setImageViewBitmap).位图也被序列化为内部包.不幸的是,这个捆绑包的尺寸限制非常小.
我不能使用setImageResource,因为我希望允许用户下载小部件的外观.
任何人都可以为此问题推荐解决方法吗?我已经为窗口小部件的每个实例使用了"新的"RemoteViews对象,但是单个实例包含太多更新.
谢谢!
Ash*_*ell 10
我发现最好的解决方法是使用setImageURI在ImageView使用对象
remoteViews.setUri(R.id.myImageView, "setImageURI", "file://blahblahblah.png");
Run Code Online (Sandbox Code Playgroud)
以下是Android Developers小组的完整讨论
你可以通过这种方式缩小图像大小来解决它:
public static Bitmap scaleDownBitmap(Bitmap photo, int newHeight, Context context) {
final float densityMultiplier = context.getResources().getDisplayMetrics().density;
int h= (int) (newHeight*densityMultiplier);
int w= (int) (h * photo.getWidth()/((double) photo.getHeight()));
photo=Bitmap.createScaledBitmap(photo, w, h, true);
return photo;
}
Run Code Online (Sandbox Code Playgroud)
选择newHeight足够小(对于它应该在屏幕上占据的每个方格约为100)并将其用于您的小部件,您的问题将得到解决:)
| 归档时间: |
|
| 查看次数: |
18699 次 |
| 最近记录: |