I am setting the profile image of an account by selecting the image from gallery as following
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.profile_image :
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY);
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == GALLERY && resultCode != 0) {
profileImage.setImageBitmap(null);
if (Image != null)
Image.recycle();
Uri mImageUri = data.getData();
try {
Image = MediaStore.Images.Media.getBitmap(this.getContentResolver(), mImageUri);
profileImage.setImageBitmap(Image);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
this works perfect but one problem is there, image height and width get changing for different image. what I want is to fix the image size and width to 150 dp? following is my xml code
<ImageView
android:id="@+id/profile_image"
android:layout_width="150dp"
android:layout_height="150dp"
app:srcCompat="@android:drawable/sym_def_app_icon"
android:clickable="true"/>