In app I have:
LinearLayout linearLayout2 = (LinearLayout) findViewById(R.id.cvLinearLayout2);
and after:
linearLayout2.setVisibility(View.GONE);
I can't find a way to bring linearLayout2 back.
Tried everything:
linearLayout2.setVisibility(View.VISIBLE);
linearLayout2.bringToFront();
linearLayout2.getParent().requestLayout();
linearLayout2.forceLayout();
linearLayout2.requestLayout();
linearLayout2.invalidate();
but with no results.
linearLayout2 have one parent linearLayout1, so I tried also:
linearLayout1.requestLayout();
linearLayout1.invalidate();
still with zero results. linearLayout2 stays GONE.
In my app I need to move linearLayout away, and then, after a while to redraw it again. Please help.
View.GONE will remove the View from the screen, and the space occupied by the View is released to other Views on screen. So, a "GONE" view cannot come back. You need to reload it.
If you want to keep the space, you can use View.INVISIBLE. Now the View is NOT removed, instead, it hides the View and display blank space.
In simple illustration, you have the following setup:
ABCD
After calling B.setVisibility(View.INVISIBLE); you will have:
A CD
But after calling B.setVisibility(View.GONE); you will get:
ACD
Setting a View's visibility to GONE should not affect it's ability to "come back" by using the method setVisibility(View.VISIBLE)
For example I have this code in one of my apps:
public void onCheckedChanged(CompoundButton checkBox, boolean isChecked{
if(checkBox == usesLocationCheckBox)
{
View view = findViewById(R.id.eventLocationOptions);
if(isChecked)
{
view.setVisibility(View.VISIBLE);
usesTimeCheckBox.setEnabled(false);
}
if(!isChecked)
{
view.setVisibility(View.GONE);
usesTimeCheckBox.setEnabled(true);
}
}}
And it works perfectly fine. Some other code your program is executing must be responsible. Edit your post with the relevant code, and we may be able to give you a better answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With