Hiding linear layout on runtime in Android

前端 未结 2 1036
南方客
南方客 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 :)

    0 讨论(0)
  • 2021-01-13 19:12

    You should use the Constants provided by View

    View.INVISBLE, View.VISIBLE, View.GONE
    

    and also invalidate your View

    0 讨论(0)
提交回复
热议问题