我是 Kivy/KivyMD 的新手。我正在尝试创建一个可滚动的 GridLayout,它将用于显示经文。我特别想使用 2 列 GridLayout。 (第 1 栏为英文经文,第 2 栏为相同经文的区域翻译)
我已经掌握了基本结构,但我终究无法弄清楚如何将行项目对齐到顶部或中心。默认情况下,它将行项目对齐到行的底部。 (如图)
如何对齐我的经文(行项目),使它们顶部对齐?
我的KV文件:
<VerseItem@MDLabel>
text: "1. I am a verse. I need to be top aligned with my sibling\n"*5
adaptive_height: True
md_bg_color: "blue"
<VerseItem2@MDLabel>
md_bg_color: "red"
text: "2 I am a Totally different verse, I need to be top aligned with my sibling"
adaptive_height: True
<ScratchLayout>
orientation:'vertical'
ScrollView:
do_scroll_y: True
MDGridLayout:
padding: "10dp"
spacing: "20dp"
height: self.minimum_height
cols:2
size_hint_y: None
VerseItem:
VerseItem2:
VerseItem:
text:"The text can change, but must be top aligned"
VerseItem2:
text: "Hello, world"*10
VerseItem:
text: "Hello, world"*4
VerseItem2:
text: "Hello, world"*15
VerseItem:
VerseItem2:
VerseItem:
text:"The text can change, but must be top aligned"
VerseItem2:
text: "Hello, world"*10
VerseItem:
text: "Hello, world"*4
VerseItem2:
text: "Hello, world"*15
我的python文件:
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
class ScratchLayout(MDBoxLayout):
pass
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return ScratchLayout()
Example().run()