Michael Maclean

Android: LinearLayouts, WebViews and black screens

Just making a quick note in case anyone else is searching for the same problem.

I have an app with an activity which previously was just a WebView, but I wanted to add some other widgets above the WebView as well, so I made an XML layout and wrapped the WebView in a LinearLayout. Upon using this as the content view, my WebView went black. Completely. This resulted in a bit of frantic Googling, whereupon I discovered that it wasn’t an unusual problem. Most of the solutions revolved around making sure the LinearLayout’s width and height were both set to fill_parent — this didn’t work for me. A little bit of investigation then lead me to discover that I’d forgotten to set the orientation on the LinearLayout. Once I’d set that, everything started working fine. A silly problem, but quite often it’s the silly ones that take the most time to figure out.