2

例如,我希望给定的位图(100x200px)始终具有以下大小:

 height = 1/10 of the screens height
 length = 1/20 of the screens length,

无论屏幕有多大,分辨率如何。如何在不为每个可绘制文件夹创建位图版本的情况下做到这一点(我已经看到所有图片仅存储在“可绘制”文件夹中的示例,因此必须在不创建每张图片的 4 个实例的情况下使用)?

谢谢您的帮助!

4

2 回答 2

1

将您的位图加载到 ImageView 并将 ImageView 的 ScaleType 设置为“FIT_XY”,它会将您的图像缩放到您的 ImageView 的任何大小。您可以通过从 WindowManager 获取屏幕尺寸来将 ImageView 尺寸设置为相对于您的屏幕尺寸

例如:-

int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
int screenHeight = getWindowManager().getDefaultDisplay().getHeight();

float newWidth = 0.05f * screenWidth; 
float newHeight = 0.10f * screenHeight;

imageview.setScaleType( ImageView.ScaleType.FIT_XY ); 
imageview.setLayoutParams(new LinearLayout.LayoutParams( (int)newWidth, (int)newHeight ));  
于 2012-10-15T11:02:43.087 回答
0

最终 int 宽度 = getWindowManager().getDefaultDisplay().getWidth();

最终 int 高度 = getWindowManager().getDefaultDisplay().getHeight();

然后使用 bitmapfactory 缩放图像

于 2012-10-14T16:57:32.937 回答