Android hide and removing the image in imageview

2020-07-02 12:09发布

How to remove a image in imageview in android and also how to hide the entire image.

Here I have placed an image in imageview by the below code.

answerState1.setBackgroundResource(R.drawable.correct);

I don't know how to remove or hide the image. Also I am entirely new to android development.

4条回答
戒情不戒烟
2楼-- · 2020-07-02 12:45

Try the following code:

ImageView im = (ImageView)findViewById(R.id.imageView1);
im.setVisibility(View.INVISIBLE);
im.getLayoutParams().height = 0;
查看更多
老娘就宠你
3楼-- · 2020-07-02 12:50

You can use answerState1.setVisibility(View.INVISIBLE); to make view invisible and answerState1.setVisibility(View.Gone); to make the view invisible.

查看更多
姐就是有狂的资本
4楼-- · 2020-07-02 12:53

You can set the visibility of an image with the following method calls:

answerState1.setVisibility(View.GONE);  // hide image (make the view gone)

answerState1.setVisibility(View.VISIBLE);  // make image visible

answerState1.setVisibility(View.INVISIBLE);  // make image invisible

In UI, you can also do something like the following:

<ImageView android:id="@+id/imgPreview" 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
android:visibility="gone"/>
查看更多
爱情/是我丢掉的垃圾
5楼-- · 2020-07-02 13:08

try this imageview.setVisibility(ImageView.INVISIBLE);

查看更多
登录 后发表回答