:github_url: https://github.com/kivymd/KivyMD/blob/master/kivymd/uix/scrollview.py

ScrollView
==========

.. py:module:: kivymd.uix.scrollview

.. autoapi-nested-parse::

   Components/ScrollView
   =====================

   .. versionadded:: 1.0.0

   :class:`~kivy.uix.scrollview.ScrollView` class equivalent.
   It implements Material Design's overscorll effect and
   simplifies working with some widget properties. For example:

   ScrollView
   ----------

   .. tabs::

       .. tab:: KV

           .. code-block:: kv

               ScrollView:
                   canvas:
                       Color:
                           rgba: app.theme_cls.primaryColor
                       Rectangle:
                           pos: self.pos
                           size: self.size

       .. tab:: Python

           .. code-block:: python

               from kivy.uix.scrollview import ScrollView
               from kivy.graphics import Color, Rectangle
               from kivy.app import App

               class MyApp(App):
                   def build(self):
                       layout = ScrollView()

                       with layout.canvas:
                           Color(*self.theme_cls.primary_color)
                           self.rect = Rectangle(pos=layout.pos, size=layout.size)

                       return layout

               MyApp().run()

   MDScrollView
   ------------

   .. tabs::

       .. tab:: Imperative python style with KV

           .. code-block:: kv

               MDScrollView:
                   md_bg_color: app.theme_cls.primaryColor

       .. tab:: Declarative python style

           .. code-block:: python

               from kivymd.uix.scrollview import MDScrollView
               from kivymd.app import MDApp

               class MyApp(App):
                   def build(self):
                       return MDScrollView(
                           md_bg_color=self.theme_cls.primaryColor
                       )

               MyApp().run()

   The stretching effect
   ---------------------

   .. tabs::

       .. tab:: Declarative Python style with KV

           .. code-block:: python

               import os
               import sys

               from kivy.core.window import Window
               from kivy import __version__ as kv__version__
               from kivy.lang import Builder
               from kivy.metrics import dp

               from kivymd.app import MDApp
               from kivymd import __version__
               from kivymd.uix.list import (
                   MDListItem,
                   MDListItemHeadlineText,
                   MDListItemSupportingText,
                   MDListItemLeadingIcon,
               )

               from materialyoucolor import __version__ as mc__version__


               MAIN_KV = '''
               MDScreen:
                   md_bg_color: app.theme_cls.backgroundColor

                   MDScrollView:
                       do_scroll_x: False

                       MDBoxLayout:
                           id: main_scroll
                           orientation: "vertical"
                           adaptive_height: True

                           MDBoxLayout:
                               adaptive_height: True

                               MDLabel:
                                   theme_font_size: "Custom"
                                   text: "OS Info"
                                   font_size: "55sp"
                                   adaptive_height: True
                                   padding: "10dp", "20dp", 0, 0

                               MDIconButton:
                                   icon: "menu"
                                   pos_hint: {"center_y": .5}
               '''


               class Example(MDApp):
                   def build(self):
                       self.theme_cls.theme_style = "Dark"
                       return Builder.load_string(MAIN_KV)

                   def on_start(self):
                       info = {
                           "Name": [
                               os.name,
                               (
                                   "microsoft"
                                   if os.name == "nt"
                                   else ("linux" if os.uname()[0] != "Darwin" else "apple")
                               ),
                           ],
                           "Architecture": [os.uname().machine, "memory"],
                           "Hostname": [os.uname().nodename, "account"],
                           "Python Version": ["v" + sys.version, "language-python"],
                           "Kivy Version": ["v" + kv__version__, "alpha-k-circle-outline"],
                           "KivyMD Version": ["v" + __version__, "material-design"],
                           "MaterialYouColor Version": ["v" + mc__version__, "invert-colors"],
                           "Pillow Version": ["Unknown", "image"],
                           "Working Directory": [os.getcwd(), "folder"],
                           "Home Directory": [os.path.expanduser("~"), "folder-account"],
                           "Environment Variables": [os.environ, "code-json"],
                       }

                       try:
                           from PIL import __version__ as pil__version_

                           info["Pillow Version"] = ["v" + pil__version_, "image"]
                       except Exception:
                           pass

                       for info_item in info:
                           self.root.ids.main_scroll.add_widget(
                               MDListItem(
                                   MDListItemLeadingIcon(
                                       icon=info[info_item][1],
                                   ),
                                   MDListItemHeadlineText(
                                       text=info_item,
                                   ),
                                   MDListItemSupportingText(
                                       text=str(info[info_item][0]),
                                   ),
                                   pos_hint={"center_x": .5, "center_y": .5},
                               )
                           )

                       Window.size = [dp(350), dp(600)]


               Example().run()

       .. tab:: Declarative python style

           .. code-block:: python

               import os
               import sys

               from kivy.core.window import Window
               from kivy import __version__ as kv__version__
               from kivy.metrics import dp

               from kivymd.app import MDApp
               from kivymd import __version__
               from kivymd.uix.boxlayout import MDBoxLayout
               from kivymd.uix.button import MDIconButton
               from kivymd.uix.label import MDLabel
               from kivymd.uix.list import (
                   MDListItem,
                   MDListItemHeadlineText,
                   MDListItemSupportingText,
                   MDListItemLeadingIcon,
               )

               from materialyoucolor import __version__ as mc__version__

               from kivymd.uix.screen import MDScreen
               from kivymd.uix.scrollview import MDScrollView


               class Example(MDApp):
                   def build(self):
                       self.theme_cls.theme_style = "Dark"
                       return (
                           MDScreen(
                               MDScrollView(
                                   MDBoxLayout(
                                       MDBoxLayout(
                                           MDLabel(
                                               theme_font_size="Custom",
                                               text="OS Info",
                                               font_size="55sp",
                                               adaptive_height=True,
                                               padding=("10dp", "20dp", 0, 0),
                                           ),
                                           MDIconButton(
                                               icon="menu",
                                               pos_hint={"center_y": .5},
                                           ),
                                           adaptive_height=True
                                       ),
                                       id="main_scroll",
                                       orientation="vertical",
                                       adaptive_height=True,
                                   ),
                                   do_scroll_x=False
                               ),
                               md_bg_color=self.theme_cls.backgroundColor
                           )
                       )

                   def on_start(self):
                       info = {
                           "Name": [
                               os.name,
                               (
                                   "microsoft"
                                   if os.name == "nt"
                                   else ("linux" if os.uname()[0] != "Darwin" else "apple")
                               ),
                           ],
                           "Architecture": [os.uname().machine, "memory"],
                           "Hostname": [os.uname().nodename, "account"],
                           "Python Version": ["v" + sys.version, "language-python"],
                           "Kivy Version": ["v" + kv__version__, "alpha-k-circle-outline"],
                           "KivyMD Version": ["v" + __version__, "material-design"],
                           "MaterialYouColor Version": ["v" + mc__version__, "invert-colors"],
                           "Pillow Version": ["Unknown", "image"],
                           "Working Directory": [os.getcwd(), "folder"],
                           "Home Directory": [os.path.expanduser("~"), "folder-account"],
                           "Environment Variables": [os.environ, "code-json"],
                       }

                       try:
                           from PIL import __version__ as pil__version_

                           info["Pillow Version"] = ["v" + pil__version_, "image"]
                       except Exception:
                           pass

                       for info_item in info:
                           self.root.get_ids().main_scroll.add_widget(
                               MDListItem(
                                   MDListItemLeadingIcon(
                                       icon=info[info_item][1],
                                   ),
                                   MDListItemHeadlineText(
                                       text=info_item,
                                   ),
                                   MDListItemSupportingText(
                                       text=str(info[info_item][0]),
                                   ),
                                   pos_hint={"center_x": .5, "center_y": .5},
                               )
                           )

                       Window.size = [dp(350), dp(600)]


               Example().run()

   .. image:: https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/stretch_over_scroll_stencil.gif
       :align: center


API - :mod:`kivymd.uix.scrollview`
----------------------------------

.. py:class:: StretchOverScrollStencil(*arg, **kwargs)




   Stretches the view on overscroll and absorbs
   velocity at start and end to convert to stretch.

   .. versionadded:: 2.0.0

   .. note:: This effect only works with
       :class:`kivymd.uix.scrollview.MDScrollView`.

   If you need any documentation please look at
   :class:`~kivy.effects.dampedscrolleffect`.

   .. py:attribute:: minimum_absorbed_velocity
      :value: 0

      

   .. py:attribute:: maximum_velocity
      :value: 10000

      

   .. py:attribute:: stretch_intensity
      :value: 0.016

      

   .. py:attribute:: exponential_scalar

      

   .. py:attribute:: scroll_friction
      :value: 0.015

      

   .. py:attribute:: approx_normailzer
      :value: 200000.0

      

   .. py:attribute:: duration_normailzer
      :value: 10

      

   .. py:attribute:: scroll_view

      

   .. py:attribute:: scroll_scale

      

   .. py:attribute:: scale_axis
      :value: 'y'

      

   .. py:attribute:: last_touch_pos

      

   .. py:method:: clamp(value, min_val=0, max_val=0)


   .. py:method:: is_top_or_bottom()


   .. py:method:: on_value(stencil, scroll_distance)


   .. py:method:: get_hw()


   .. py:method:: set_scale_origin()


   .. py:method:: absorb_impact()


   .. py:method:: get_component(pos)


   .. py:method:: can_stretch_touch(touch)


   .. py:method:: convert_overscroll(touch)


   .. py:method:: reset_scale(*arg)



.. py:class:: StretchOverScrollBehavior(*args, **kwargs)


   Shared overscroll-stretch setup for ScrollView-based widgets.

   .. py:method:: on_touch_down(touch)


   .. py:method:: on_touch_move(touch)


   .. py:method:: on_touch_up(touch)



.. py:class:: MDScrollView(*args, **kwargs)




   An approximate implementation to Material Design's overscorll effect.

   For more information, see in the
   :class:`~kivymd.uix.behaviors.declarative_behavior.DeclarativeBehavior` and
   :class:`~kivymd.uix.behaviors.backgroundcolor_behavior.BackgroundColorBehavior` and
   :class:`~kivy.uix.scrollview.ScrollView`
   classes documentation.



