Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 屏幕大小百分比计算器返回错误大小_Java_Math_Bitmap - Fatal编程技术网

Java 屏幕大小百分比计算器返回错误大小

Java 屏幕大小百分比计算器返回错误大小,java,math,bitmap,Java,Math,Bitmap,我有一个用于从drawable文件夹返回位图的函数。(我不使用可绘制的DPI文件夹,浪费时间) 不管函数如何检索位图,位图都会以视图端口大小的指定百分比返回 此时返回的值小于指定的百分比,例如地面元素: 百分比应为宽度的100%,即480像素。很明显这应该是480,但它返回400?我一定错过了一些简单的数学知识,或者下面的代码:(我也应该使用createscaledbitmap吗?) 正在做整数除法 你可能想要 _newWidth = (screen_dimention / 100.0) * p

我有一个用于从drawable文件夹返回位图的函数。(我不使用可绘制的DPI文件夹,浪费时间)

不管函数如何检索位图,位图都会以视图端口大小的指定百分比返回

此时返回的值小于指定的百分比,例如地面元素:

百分比应为宽度的100%,即480像素。很明显这应该是480,但它返回400?我一定错过了一些简单的数学知识,或者下面的代码:(我也应该使用createscaledbitmap吗?)

正在做整数除法

你可能想要

_newWidth = (screen_dimention / 100.0) * percentage;
_newWidth = (screen_dimention * percentage) / 100;
或者,如果_newWidth实际上应该被截断为整数,您可能需要

_newWidth = (screen_dimention / 100.0) * percentage;
_newWidth = (screen_dimention * percentage) / 100;
稍后进行截断

正在做整数除法

你可能想要

_newWidth = (screen_dimention / 100.0) * percentage;
_newWidth = (screen_dimention * percentage) / 100;
或者,如果_newWidth实际上应该被截断为整数,您可能需要

_newWidth = (screen_dimention / 100.0) * percentage;
_newWidth = (screen_dimention * percentage) / 100;

以后再进行截断。

谢谢你修复了它,我知道它是这样简单的东西,就是想不出来。谢谢你修复了它,我知道它是这样简单的东西,就是想不出来。