I'm trying to get a scroll bar working in my user interface. My user interface is going to be able to stretch from how much text a user puts into it. But the way it stretches doesn't cause Scrollview to "activate".
This code just increases the widget size after 4 seconds to test this.
First it looks like Then it looks like
Notice that we now can't see the last list item. But the scroll bar should be visible on the right of the screen indicating that we can scroll down to view it. But we can't. Scrollview doesn't know the content has pushed past the bottom of the screen.
The Code
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.clock import Clock
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ObjectProperty
from lib.modules.adaptive_grid_layout import Adaptive_GridLayout
#This should have not enough content to scroll at first,
#but the size change should push some content past the border
Builder.load_string('''
<GrowingLabel>:
padding: 10, 5
size_hint_y: None
text_size: self.width, None
group: 'test'
canvas.before:
Color:
rgba: .7, .7, .7, 1
Rectangle:
pos: self.pos
size: self.size
<Controller>:
layout_content: layout_content
BoxLayout:
id: bl
orientation: 'vertical'
padding: 10, 10
row_default_height: '48dp'
row_force_default: True
spacing: 10, 10
ScrollView:
size: self.size
GridLayout:
id: layout_content
size_hint_y: None
cols: 1
spacing: 0, 0
padding: 0, 0
Adaptive_GridLayout:
id: Row2
cols: 1
grow_rows: True
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
GrowingLabel:
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dkdsjahf lkasjkat"
Label:
height: 20
text: "Lorem ipsdodo dod dodo do dodt"
Label:
height: 20
text: "Lorem ipsdkjwww ww woij ksdsdf sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Lorem ipsum dolor sit amet"
Label:
height: 20
text: "Last List item"
''')
class GrowingLabel(Label):
def __init__(self, **kwargs):
super(GrowingLabel, self).__init__(**kwargs)
#self.size_hint_y = None
self.height = 20
Clock.schedule_once(lambda dt: self.changeHeight(120), timeout=4)
def changeHeight(self, p_val):
self.height = p_val
class Controller(FloatLayout):
layout_content=ObjectProperty(None)
def __init__(self, **kwargs):
super(Controller, self).__init__(**kwargs)
self.layout_content.bind(minimum_height=self.layout_content.setter('height'))
class Nested2App(App):
def build(self):
return Controller()
if __name__ == '__main__':
Nested2App().run()
Note: I'm using a custom layout called Adaptive_GridLayout that deals with scaling problems you can find here .
My Question to you
Is there some way to manually trigger this displaying of the scroll bar in scrollview? Or is there some way to refresh scrollview so it notices how big it's contents are and respond appropriately?
After downloading the Adaptive_GridLayout
and making the change suggested in my comment above:
Adaptive_GridLayout:
id: Row2
cols: 1
grow_rows: True
size_hint: 1.0, None
height: self.minimum_height
The ScrollView
works after the GrowingLabel
changed its height
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.