Я пытаюсь создать макет в Kivy / KivyMD, который будет отзывчивым, центрированным и прокручиваемым. До сих пор я разработал два макета, один, который центрирует BoxLayout в FloatLayout, и его можно красиво изменить, но он не прокручивается. Я также разработал макет, который представляет собой GridLayout в ScrollView, он прекрасно изменяет размеры, но при больших размерах окна он не центрирует GridLayout должным образом.
Я попытался поместить BoxLayout в FloatLayout вScrollView, он прекрасно изменяет размеры, НО полоса прокрутки не работает.
Я до сих пор не смог объединить центрированный макет с изменяемым размером в правильно работающем просмотре прокрутки. Как мне это сделать?
Вот мой пример scrollview:
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.scrollview import ScrollView
from kivy.uix.floatlayout import FloatLayout
LIPSUM = """Very long lipsum..."""
Builder.load_string("""
<ExampleScroll@ScrollView>:
do_scroll_x: False
bar_width: 10
bar_color: app.theme_cls.primary_color
bar_color_acrive: app.theme_cls.accent_color
effect_cls: "DampedScrollEffect"
scroll_type: ['bars']
GridLayout: # If FloatLayout and BoxLayout, doesn't scroll!
cols: 1
size_hint_y: None
height: self.minimum_height
size_hint_x: .75
size_hint_max_x: dp(800)
size_hint_min_x: min(dp(400), root.width)
pos_hint: {'center_x': .5} # Fails to center layout
padding: 0, dp(16), 0, 0
MDLabel:
text: app.label_text + app.label_text
halign: 'justify'
padding: dp(16), dp(16)
markup: True
font_style: 'Body1'
theme_text_color: 'Primary'
size_hint_y: None
height: self.texture_size[1]
text_size: self.size
MDLabel:
text: app.label_text + app.label_text
halign: 'justify'
padding: dp(16), dp(16)
markup: True
font_style: 'Body1'
theme_text_color: 'Primary'
size_hint_y: None
height: self.texture_size[1]
text_size: self.size
Widget
""")
class ExampleScroll(ScrollView):
pass
class Example(MDApp):
title = "Dialogs"
label_text = LIPSUM
def build(self):
return ExampleScroll()
Example().run()
Вот мой центрирующий пример:
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.scrollview import ScrollView
from kivy.uix.floatlayout import FloatLayout
LIPSUM = """Very long lipsum..."""
Builder.load_string("""
<ExampleCenter@FloatLayout>:
BoxLayout:
orientation: 'vertical'
# Gives the BoxLayout a max and min width that is responsive
size_hint_x: .75
size_hint_max_x: dp(800)
size_hint_min_x: min(dp(400), root.width)
# Centers the BoxLayout horizontally responsively
pos_hint: {'center_x': .5}
padding: 0, dp(16), 0, 0
MDLabel:
text: app.label_text + app.label_text
halign: 'justify'
padding: dp(16), dp(16)
markup: True
font_style: 'Body1'
theme_text_color: 'Primary'
size_hint_y: None
height: self.texture_size[1]
MDLabel:
text: app.label_text + app.label_text
halign: 'justify'
padding: dp(16), dp(16)
markup: True
font_style: 'Body1'
theme_text_color: 'Primary'
size_hint_y: None
height: self.texture_size[1]
Widget
""")
class ExampleCenter(FloatLayout):
pass
class Example(MDApp):
title = "Dialogs"
label_text = LIPSUM
def build(self):
return ExampleCenter()
Example().run()
Как я могу скомпилировать оба эти изаставить это работать?