例如,我希望给定的位图(100x200px)始终具有以下大小:
height = 1/10 of the screens height
length = 1/20 of the screens length,
无论屏幕有多大,分辨率如何。如何在不为每个可绘制文件夹创建位图版本的情况下执行此操作(我见过所有图片仅存储在"可绘制"文件夹中的示例,因此必须在不创建每张图片的 4 个实例的情况下离开使用)?
感谢您的帮助!
将位图加载到 ImageView 中,并将 ImageView 的 ScaleType 设置为 'FIT_XY',它会将您的图像缩放到您的 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 ));
final int width = getWindowManager().getDefaultDisplay().getWidth();
final int height = getWindowManager().getDefaultDisplay().getHeight();
然后使用位图工厂缩放图像