我在个人资料活动中有一个循环的ImageView:
但如果我更改了配置文件图像,我就丢失了圆形框架:(
我的代码:
public void setCircularImage(ImageView imageViewCircularProfile){
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.profile_pic);
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
circularBitmapDrawable.setCircular(true);
imageViewCircularProfile.setImageDrawable(circularBitmapDrawable);
}
更改图像方法:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.action_changePic){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Selecione"), SELECT_PICTURE);
}
return super.onOptionsItemSelected(item);
}
onActivityResult:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_PICTURE && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
imageViewCircularProfile.setImageBitmap(bitmap);
setCircularImage(imageViewCircularProfile);
} catch (IOException e) {
e.printStackTrace();
}
}
}
任何想法?
谢谢!