我正在构建一个Android应用程序。在一个Activity中,我有一个图像按钮。当我单击它时,画廊打开,我可以选择一张图像。然后,我将该图像设置为图像按钮的新图像。
问题是图像在我的Activity中显得太大了。如何使它适合我的图像按钮?
我正在构建一个Android应用程序。在一个Activity中,我有一个图像按钮。当我单击它时,画廊打开,我可以选择一张图像。然后,我将该图像设置为图像按钮的新图像。 问题是图像在我的Activity中显得太大了。如何使它适合我的图像按钮?
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case SELECT_PHOTO:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
mImageButton.setImageBitmap(yourSelectedImage);
}
}
}
requiredSize
参数的含义是什么? - Tony DinhBitmapFactory.Options
? - Dr4ke the b4dass