如何在android布局中缩小图像的大小?
我有一个图像,我想在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
如果我指定某个宽度和高度,它将裁剪图像而不是收缩图像请使用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);
根据需要缩放的百分比更改倍数值
此外,有关更多选项,请参阅此链接。