Hiding linear layout on runtime in Android

前端 未结 2 1035
南方客
南方客 2021-01-13 18:45

I am having following layout


    

        
2条回答
  •  清酒与你
    2021-01-13 18:55

    It looks like you're setting the wrong constants for changing view visibility.

    GONE == 8
    INVISIBLE == 4
    VISIBLE == 0
    

    However, you should never rely on the actual values that Android happened to designate to represent their constants. Instead use the the values defined in the View class: View.VISIBLE, View.INVISIBLE, and View.GONE.

    // snip...
    if(visibility == View.VISIBLE)
    {
        visibility = View.GONE;
    }
    else
    {
        visibility = View.VISIBLE;
    }
    ll.setVisibility(visibility);
    

    And don't forget to call invalidate() on the view :)

提交回复
热议问题