我从图库中选择图片如下android:如何以编程方式固定大小的图像视图?
@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();
}
}
}
这个完美的作品,但一个问题是存在的,图像的高度和宽度得到改变为不同的图像设置帐户的个人资料图片。我想要的是将图像大小和宽度固定为150 dp? 下面是我的XML代码
<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"/>
请参阅[此](http://stackoverflow.com/a/41038654/5460053)调整图像大小。 –