按钮关闭在imageview从照相机或画廊

时间:2016-10-15 22:22:03

标签: android button uiimageview imageview android-imageview

美好的一天! 需要添加一个按钮来删除图像视图(图片)。我不知道怎么做。 Thx求助= 3

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && requestCode == 1 && null != data) {
        decodeUri(data.getData());
    }
    if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {

        ImageView image = (ImageView)findViewById(R.id.photka);


        Bitmap photo = (Bitmap) data.getExtras().get("data");


        image.setImageBitmap(photo);

    }
}

http://i.imgur.com/Y9h9Bcp.png http://i.imgur.com/Y9h9Bcp.png

3 个答案:

答案 0 :(得分:0)

您可以使用以下任何选项删除ImageView

  1. 您可以像这样点击按钮时将ImageView的可见性设置为Gone

    final ImageView image = (ImageView)findViewById(R.id.photka);
    
    Button removeImageButton = (Button)findViewById(R.id.Button_id);
    removeImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            image.setVisibility(View.GONE);
        }
    });
    
  2. 您可以从其父视图中删除ImageView

    final ViewGroup parent = (ViewGroup)findViewById(R.id.root_parent);
    
    final ImageView image = (ImageView)findViewById(R.id.photka);
    
    Button removeImageButton = (Button)findViewById(R.id.Button_id);
    removeImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            parent.removeView(image);
        }
    });
    

答案 1 :(得分:0)

为我的活动添加代码

ImageView close =(ImageView)findViewById(R.id.close); ImageView image =(ImageView)findViewById(R.id.photka);

image.setImageBitmap(位图);             close.setVisibility(View.VISIBLE);

答案 2 :(得分:0)

最终ImageView image =(ImageView)findViewById(R.id.photka);             最终ImageView close =(ImageView)findViewById(R.id.close);

        Bitmap photo = (Bitmap) data.getExtras().get("data");


        image.setImageBitmap(photo); 
        image.setVisibility(View.VISIBLE);   
        close.setVisibility(View.VISIBLE); 
        close.setOnClickListener(new View.OnClickListener() {  
            @Override
            public void onClick(View v) {
                image.setVisibility(View.GONE);
                close.setVisibility(View.GONE);
                return;
            }
        });

需要使用Visibility.Gone

添加从堆栈中删除