使用RemoteViews在窗口小部件上的9补丁位图

时间:2010-07-28 21:43:13

标签: android bitmap nine-patch

我有一个带有ImageView的小部件。我将此ImageView设置为从9补丁PNG资源创建的位图。图像设置正确但未正确拉伸 - 即整个图像被拉伸而不是像我的9补丁PNG中定义的那样。如果我只是将9补丁图像设置为资源,它就可以工作。我该如何解决这个问题?

// Does not work (9-patch does not display correctly)
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.someNinePatch);
remoteViews.setImageViewBitmap(R.id.someImageView, bitmap);

// Works (9-patch displays correctly)
remoteViews.setImageViewResource(R.id.someImageView, R.drawable.someNinePatch);

1 个答案:

答案 0 :(得分:1)

Android凭借资源上的.9.png文件扩展名知道PNG是一个九补丁。我不知道有什么方法可以在资源之外使用九个补丁图像,因为Android不会有文件扩展名,也不会知道图像是九个补丁。

相关问题