Skip to content Skip to sidebar Skip to footer

Can I Hide An Image Button On A Layout, (dimensions And Background) Until A Call To Set Visible?

I have a hidden image button in one of my xmls layouts, with a background set to a drawable image. I set the visibility to invisible, as I only want the image to display every onc

Solution 1:

Try setting the visibility to GONE

Solution 2:

Don't set the width/height to zero, that's ugly. The view will always take up the space, unless you change the visibility setting. This is the code you want:

myImageButton.setVisibility(View.GONE);

View.GONE - invisible, takes up no space View.INVISIBLE - invisible, but still takes up space View.VISIBLE - use this to bring it back

Solution 3:

All views, including ImageButton, inherit from android.view.View, so they all have a visibility attribute that can be set. Instead of setting the visibility of the drawable resource, set it on the ImageButton.

Solution 4:

Set Visibility property of Imageview like this in java

imgView.setVisibility(View.VISIBLE);
imgView.setVisibility(View.INVISIBLE);
imgView.setVisibility(View.GONE);

Or like this in XML

android:visibility="visible"android:visibility="gone"android:visibility="invisible"

Result for each will be like this

enter image description here

Post a Comment for "Can I Hide An Image Button On A Layout, (dimensions And Background) Until A Call To Set Visible?"