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

前端 未结 4 1499
日久生厌
日久生厌 2021-02-06 15:45

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

4条回答
  •  伪装坚强ぢ
    2021-02-06 15:49

    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

提交回复
热议问题