2010-07-28 22 views
0

我有一个带有ImageView的小部件。我将此ImageView设置为从9修补程序PNG资源创建的位图。图像设置正确,但没有正确拉伸 - 即整个图像被拉伸,而不是像我的9修补程序PNG中定义的那样。如果我只是将9-patch镜像设置为资源,它就可以工作。我怎样才能解决这个问题?使用RemoteViews在一个小部件上的9-patch位图

// 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

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

+0

该资源的扩展名为.9.png,我只是将它用作位图。 – 2010-07-29 18:38:00

+1

@Isaac Walter:但是你通过将它加载到一个'Bitmap'对象中而失去了扩展。 AFAIK,一个'Bitmap'对象不知道它是来自一个普通的PNG,一个九块PNG,一个JPEG,一个GIF或其他东西。 – CommonsWare 2010-07-29 21:37:09

相关问题