android setVisibility does not display if initially set to invisble
Got it. You have to set the visibility of all the items in the layout, not just the layout. So this code worked:
if (mLayoutLights.getVisibility() == View.VISIBLE) {
((Button) findViewById(R.id.btnLightsOK)).setVisibility(View.GONE);
((Button) findViewById(R.id.btnLightsCnc)).setVisibility(View.GONE);
mLayoutLights.setVisibility(View.GONE);
} else {
mLayoutLights.setVisibility(View.VISIBLE);
((Button) findViewById(R.id.btnLightsOK)).setVisibility(View.VISIBLE);
((Button) findViewById(R.id.btnLightsCnc)).setVisibility(View.VISIBLE);
}
In my case, with a plain SurfaceView, I just set the View to GONE in xml, not INVISIBLE. Then I can set VISIBILITY correctly after that.
I would suggest trying three independent things.
- Changing layout width and height to wrap content as it could be an issue with matching the parent.
- Calling bringToFront on the view
- Wrapping the surfaceView in a FrameLayout (this is related to #2, but it still might help)
Had similar error but it was due to my silly mistake of not using the UiThread.
Activity act = (Activity)context;
act.runOnUiThread(new Runnable(){
@Override
public void run() {
mLayoutLights.setVisibility(View.VISIBLE);
} });