kivy - 覆盖kivymd中标签的工具栏
问题描述
我的 MDToolbar 覆盖了标签的最上部,我希望标签的文本出现在工具栏下方,pos_hint 也不起作用我想设置标签文本的位置我也想在左侧提供填充右边是我在 .kv 文件中的代码
<MainScreen>:
BoxLayout:
canvas:
Color:
rgb: 0, 0, 0, 0
Rectangle:
pos: root.pos
size: root.size
ScrollView:
Label:
text:
"""
A boy and a girl were playing together. The boy had a collection of marbles. The girl has some
sweets with her. The boy told the girl that he would give her all his marbles in exchange for the
sweets with her. The girl agreed.
The boy kept the most beautiful and the biggest marbles with him and gave her the remaining marbles.
The girl gave him all her sweets as she promised. That night the girl slept peacefully. But the boy
could not sleep as he kept wondering if the girl has hidden some sweets from him the way he had
hidden the best marbles from her.
Moral of the Story :
If you do not give 100 percent in a relationship, you will always kept doubting if the other person
has given her / his hundred percent. This is applicable for any relationship like love, employee –
employer, friendship, family, countries, etc…
"""
font_size: '20sp'
height: self.texture_size[1]
size: self.texture_size
text_size: root.width, None
size_hint_x: 1.0
size_hint_y: None
halign: "auto"
valign: "middle"
ScreenManager:
id: screen_manager
MainScreen:
name: 'main'
NavigationLayout:
ScreenManager:
Screen:
MDToolbar:
title: "Story"
anchor_title: 'left'
pos_hint: {"top": 1}
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state()]]
MDNavigationDrawer:
title: 'Story A Day'
id: nav_drawer
swipe_distance: 10
ContentNavigationDrawer:
id: content_drawer
screen_manager: screen_manager
nav_drawer: nav_drawer
解决方案
问题是你的 'kv' 文件有两个规则来构建你的MainScreen
,并且都在执行。你应该把这两个规则合二为一,这样你就可以参考不同的部分MainScreen
来帮助定位。例如,在其下方添加一个id
允许定位MDToolbar
。ScrollView
像这样:
<MainScreen>:
BoxLayout:
canvas:
Color:
rgb: 0, 0, 0, 0
Rectangle:
pos: root.pos
size: root.size
ScreenManager:
id: screen_manager
MainScreen:
name: 'main'
NavigationLayout:
ScreenManager:
Screen:
MDToolbar:
id: toolbar # id for use below
title: "Story"
anchor_title: 'left'
pos_hint: {"top": 1}
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state()]]
ScrollView:
# use toolbar id to position the ScrollView
pos_hint: {'top': 1.0 - toolbar.height / self.parent.height}
Label:
text:
"""
A boy and a girl were playing together. The boy had a collection of marbles. The girl has some
sweets with her. The boy told the girl that he would give her all his marbles in exchange for the
sweets with her. The girl agreed.
.
.
.
您的kv
文件的功能过于复杂。我没有做任何简化,因为你可能有你这样做的理由。
推荐阅读
- r - 在彼此之上绘制单变量时间序列周期(天),并在周期之间平滑过渡
- python - 使用 pdftabextract 提取 PDF 表格数据
- git - 推送的更改是否等于删除和或替换文件内容?
- javascript - 如何将字典从 Django 视图传递到 JavaScript 并使用键访问字典值
- javascript - TS2769:没有重载匹配此调用
- sql - 在 postgreSQL 查询中没有数据的月份返回 0
- c++ - gps.location.isUpdated() 条件不起作用
- json - 如何在 Blazor 中使用 Http.GetFromJsonAsync 将模型对象传递给控制器函数
- ios - 使用两个标准对列表进行排序-objective-c
- python - 使用 Pyplot 绘制隐藏单元激活