我正在建造一個android的地方。在一項活動中,我有一個圖像按鈕。當我點擊它時,畫廊打開,我可以選擇一個圖像。然後,我將該圖像設置爲圖像按鈕的新圖像。 問題是在我的活動中圖像顯得太大了。我如何使它適合我的圖像按鈕?如何調整我從Android中的圖庫中挑選的圖像?
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'參數是什麼意思嗎? – TrungDQ