Can I hide an image button on a layout, (dimensions and background) until a call to set visible?

▼魔方 西西 提交于 2019-12-03 03:50:52

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.

Try setting the visibility to GONE

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!