我有2个按钮:
问题是当我拍摄一张照片时正在显示它,但是当我拍摄另一张照片时它正在替换当前照片,但是我想要的是这些照片位于彼此之间。因此,例如,我从图库中选择1张图片,然后拍摄2张图片,我想查看3张图片,但是找不到正确的解决方案。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnCamera = findViewById(R.id.btnCamera);
imageView = (ImageView)findViewById(R.id.imageView);
btnTakeImg = (Button)findViewById(R.id.btnTakeImg);
// Open camera and take picture
btnCamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
// Pick image from gallery
btnTakeImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openGallery();
}
});
}
private void openGallery() {
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_IMAGE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK && requestCode == PICK_IMAGE) {
imageUri = data.getData();
imageView.setImageURI(imageUri);
}
if(resultCode == RESULT_OK && requestCode == 0) {
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
}