Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.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
如何在android布局中缩小图像的大小?_Android_Image_Android Layout_Layout_Imageview - Fatal编程技术网

如何在android布局中缩小图像的大小?

如何在android布局中缩小图像的大小?,android,image,android-layout,layout,imageview,Android,Image,Android Layout,Layout,Imageview,我有一个图像,我想在android布局中显示 但我想让它比原来的尺寸小一些 我该怎么做 如果我指定某个宽度和高度,它将裁剪图像而不是收缩图像请使用scaleType属性定义ImageView的缩放,例如: android:scaleType="fitCenter" 请参见使用scaleType属性定义ImageView的缩放,例如: android:scaleType="fitCenter" 请参见您可以使用下面的代码示例将图像缩放到80%的大小 int srcWidth = srcBitm

我有一个图像,我想在android布局中显示

但我想让它比原来的尺寸小一些

我该怎么做


如果我指定某个宽度和高度,它将裁剪图像而不是收缩图像

请使用scaleType属性定义ImageView的缩放,例如:

android:scaleType="fitCenter"

请参见使用scaleType属性定义ImageView的缩放,例如:

android:scaleType="fitCenter"

请参见

您可以使用下面的代码示例将图像缩放到80%的大小

int srcWidth = srcBitmap.getWidth();
int srcHeight = srcBitmap.getHeight();
int dstWidth = (int)(srcWidth*0.8f);
int dstHeight = (int)(srcHeight*0.8f);
Bitmap dstBitmap = Bitmap.createScaledBitmap(srcBitmap, dstWidth, dstHeight, true);
根据需要缩放的百分比更改倍数值

此外,有关更多选项,请参阅此链接。

您可以使用下面的代码示例将图像缩放到80%大小

int srcWidth = srcBitmap.getWidth();
int srcHeight = srcBitmap.getHeight();
int dstWidth = (int)(srcWidth*0.8f);
int dstHeight = (int)(srcHeight*0.8f);
Bitmap dstBitmap = Bitmap.createScaledBitmap(srcBitmap, dstWidth, dstHeight, true);
根据需要缩放的百分比更改倍数值

此外,有关更多选项,请参阅此链接。