Search code examples
androidandroid-layoutandroid-3.0-honeycombandroid-fragmentsnine-patch

Layout background resource flickers in and out


In my activity designed for use on tablets I call setContentView on a LinearLayout defined in XML that contains references to a few different fragments. Each fragment reference in the LinearLayout has its width set to 0dp and has a weight specified.

These fragments also use LinearLayouts for their views. In the XML for those, I set the background as a nine-patch image.

What happens when I run the app is that portions of the nine-patch literally come and go randomly and it's driving me crazy! The fragment on the left contains a WebView and a ScrollView, and the fragment on the right contains a WebView and a ViewPager. Sometimes when the activity loads everything is drawn correctly, but other times there will be no background on the right fragment. Sometimes half of the background is drawn for the right fragment, and then when I interact with the left fragment, it may disappear and reappear!

I've spent a lot of time trying to figure out what is happening and if I am doing something wrong. Has anyone else ever seen this or corrected it?

Thank you!


Solution

  • I set the app theme to use a null background and got rid of a fade-in animation I was using after setContentView. So I just had to be careful to explicitly set the background in other layouts. Madness.

    <style name="TabletTheme" parent="android:Theme.Holo.Light">
        <item name="android:windowBackground">@null</item>
    </style>