如何使用两个不同的按钮在两个单独的图像视图上添加两个图像
问题描述:
如何使用两个不同的按钮在两个单独的图像视图上添加两个图像?如何使用两个不同的按钮在两个单独的图像视图上添加两个图像
我使用下面的代码来裁剪和设置图像,仅用于单个按钮和单个图像视图。
那么我应该怎么做两个单独的图像视图与单个屏幕上的两个单独的按钮?
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 0 && resultCode == RESULT_OK)
CropImage();
else if(requestCode == 2)
{
if(data != null)
{
uri = data.getData();
CropImage();
}
}
else if (requestCode == 1)
{
if(data != null)
{
Bundle bundle = data.getExtras();
Bitmap bitmap = bundle.getParcelable("data");
ImageView imageView = (ImageView) findViewById(R.id.imgHead);
imageView.setImageBitmap(bitmap);
}
}
}
private void CropImage() {
try{
CropIntent = new Intent("com.android.camera.action.CROP");
CropIntent.setDataAndType(uri,"image/*");
CropIntent.putExtra("crop","true");
CropIntent.putExtra("outputX",180);
CropIntent.putExtra("outputY",180);
CropIntent.putExtra("aspectX",3);
CropIntent.putExtra("aspectY",3);
CropIntent.putExtra("scaleUpIfNeeded",true);
CropIntent.putExtra("return-data",true);
startActivityForResult(CropIntent,1);
}
catch (ActivityNotFoundException ex)
{
}
}
private void GalleryOpen() {
GalIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(GalIntent,"Select Image from Gallery"),2);
}
答
您可以保留一个全局布尔变量buttonOne并将其设置为默认值false。现在,如果buttonOne被点击,请设置buttonOne =True
。在此之后,在你的onActivityResult()
方法,添加其他条件语句
if (buttonOne){
imageViewOne.setImage();
}
else if(!buttonOne){
imageViewTwo.setImage();
}
我希望这会工作,如果我理解正确你的问题。
+0
我还没有得到它可以请你帮我 –
嗨Sandeep,我删除了图像链接,因为它似乎只是你包含的代码的一部分的屏幕截图。如果这是不正确的,请在相关代码中作为文本[编辑],而不是*图像。 – whrrgarbl