はじめまして。えなかと申します。
> ImageLayoutには別の画像(b)をすでに表示させていますが、
> 同じ場所に画像(a)を表示させたいです。
> ImageLayoutに画像(a)を貼り付けたら、画像(b)はもう必要ありません。
ImageLayoutというのは、
ImageViewが配置されているLinearLayoutか何かでしょうか?
コードを見させていただきましたが、
同じ場所に表示させたいということなのであれば、
新しくImageViewを生成しなくても、
取得したBitmapを改めてsetImageBitmapすれば上書きできます。
下記のような方法はどうでしょうか?
参考になれば幸いです。
public class ImageTestActivity extends Activity {
LinearLayout Imagelayout;
Bitmap mBitmap;
ImageView mImageView;
private Button button;
int REQUEST_PHOTO = 1;
private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Imagelayout = (LinearLayout) findViewById(R.id.imagelayout);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.icon);
button = new Button(this);
button.setText("ギャラリー呼び出し");
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, REQUEST_PHOTO);
}
});
Imagelayout.addView(button);
mImageView = new ImageView(this);
mImageView.setImageBitmap(bitmap);
mImageView.setLayoutParams(new LinearLayout.LayoutParams(FP, WC));
Imagelayout.addView(mImageView);
}
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_PHOTO) {
if (resultCode == RESULT_OK) {
Uri photoUri = (Uri) data.getData();
InputStream in = null;
try {
in = getContentResolver().openInputStream(photoUri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
Bitmap image = BitmapFactory
.decodeStream(in, null, options);
in.close();
mImageView.setImageBitmap(image);
} catch (FileNotFoundException e) {
} catch (IOException e) {