我有 2 个按钮:
- 1个按钮我可以拍照
- 在另一个按钮上,我可以从图库中选择图片。
问题是当我拍照时它正在显示它,但是当我拍摄另一张照片时它正在替换当前图片,但我想要的是图片彼此下方。例如,我从图库中选择 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);
}
}