title: Kivy background in scroll view
body: <p><em>Summary of test application:</em> I am writing a Kivy app with a scrollable view (named <code>Scroller</code>) with many fields (named <code>Field</code>) to look at. These separate fields are really difficult to distinguish on occasion, so I decided to use alternating background colors for each field to help distinguish each other. My testing application uses 20 individual fields each of which alternates between dark grey and darker grey.</p>
  
  <p><em>Testing trials:</em>
  Starting the application, the program looks great. The alternating background appear just fine. Even when I scroll down the application looks fine. However, the application seems to get bizarre when I scroll up on the application. The text scrolls with the application, but the background does not. Even better (sarcastically), the text starts to fade away into their neighbors background. The problem just seems to vanish when I scroll down again (passed the point of the furthest scroll up point).</p>
  
  <p><em>Brief problem description</em>: The <code>Field</code>'s "background color" messes up the application during scrolling up events.</p>
  
  <p><em>Side note:</em> I have also noticed that the application got a little sluggish after scrolling too much. I am not that familiar with the drawing cycle of Kivy, but blitting backgrounds should not yield an excessive slowdown.</p>
  
  <p><em>Testing application:</em></p>
  
  <pre><code>import kivy
  kivy.require('1.0.7')
  
  from kivy.app import App
  from kivy.uix.gridlayout import GridLayout
  from kivy.uix.scrollview import ScrollView
  from kivy.uix.label import Label
  from kivy.uix.button import Button
  from kivy.graphics import Color, Rectangle
  
  class Main(App):
      def build(self):
          self.root = GridLayout(rows = 1)
          self.root.add_widget(Scroller())
          return self.root
  
  class Scroller(ScrollView):
      def __init__(self):
          ScrollView.__init__(self)
          self.view = GridLayout(cols = 1, size_hint = (1, None))
          self.add_widget(self.view)
          self.view.bind(minimum_height = self.view.setter('height'))
  
          for i in range(20):
              self.view.add_widget(Field('Test field {}'.format(i),i%2 is 0))
  
  class Field(GridLayout):
      def __init__(self, name, bg):
          assert isinstance(name, str)
          assert isinstance(bg, bool)
          self.bg = bg
          GridLayout.__init__(self,
                              rows = 1,
                              padding = 10,
                              size = (0, 60),
                              size_hint = (1, None))
          self.add_widget(Label(text = name))
          self.add_widget(Button(text = 'Test button',
                                 size = (200, 0),
                                 size_hint = (None, 1)))
          self.bind(pos = self.change_background)
          self.bind(size = self.change_background)
  
      def change_background(self, *args):
          with self.canvas.before:
              if self.bg:
                  Color(0.2, 0.2, 0.2, mode = 'rgb')
              else:
                  Color(0.1, 0.1, 0.1, mode = 'rgb')
              Rectangle(pos = self.pos, size = self.size)
  
  if __name__ in ('__main__', '__android__'):
      app = Main()
      app.run()
  </code></pre>