kivy - 带有两个标签并同时滚动的 Kivy ScrollView?
问题描述
我创建了一个 UI,它在下部区域显示两个带有长文本的标签。两个标签都在单独的滚动视图中,因此可以滚动。如何将两个标签组合成一个滚动视图,以便两个标签同时滚动?我需要围绕滚动视图创建另一个布局吗?
这是我的kv:
<Button>:
font_size: 20
color: 0.1,0.5,0.6,1
size_hint: 0.3,0.1
<Label>:
size_hint: 0.1,0.1
<TextInput>:
size_hint: 1,0.1
<PopupBox>:
size_hint: .2, .15
auto_dismiss: True
title: 'Please wait'
Label:
pos_hint: {"x":0.5, "top":0.7}
text: 'Creating the data...'
<FloatLayout>:
canvas:
Color:
rgba: 0.15, 0.15, 0.15, 0.15
Rectangle:
size: self.size
pos: self.pos
Label:
text: "Label 1"
size_hint: 0.1,0.1
pos_hint: {"x":0.0, "top":1}
TextInput:
id: input1
pos_hint: {"x":0.11, "top":1}
multiline: True
Label:
text: "Label 2"
size_hint: 0.1,0.1
pos_hint: {"x":0.0, "top":0.9}
TextInput:
id: input2
pos_hint: {"x":0.11, "top":0.9}
multiline: True
Label:
text: "Label 3"
size_hint: 0.11, None
pos_hint: {"x":0, "top":0.8}
height: 30
TextInput:
id: input3
text: "|"
pos_hint: {"x":0.11, "top":0.8}
size_hint: 0.03, None
height: 30
Button:
text: "Clear"
on_press: app.clear_inputs()
pos_hint: {"x":0.15, "top":0.8}
size_hint: 0.1, None
height: 30
Label:
id: dd_label
text: "dd"
pos_hint: {"x":0.7, "top":0.8}
size_hint: 0.1, None
height: 30
Button:
text: "Comp"
on_press: app.start_second_thread()
pos_hint: {"x":0, "top":0.76}
size_hint: 1, None
height: 50
Button:
text: "So"
on_press: app.show_popup()
pos_hint: {"x":0, "top":0.69}
size_hint: 0.1, None
height: 25
GridLayout:
cols: 2
size_hint: 1, 0.67
ScrollView:
size_hint: (1, 1)
bar_width: 10
bar_color: 0.1, 0.1, 0.1, 0.1
bar_inactive_color: 0.15, 0.15, 0.15, 0.15
effect_cls: "ScrollEffect"
scroll_type: ['bars']
Label:
id: f_output1
text: "long text1 \n" * 100
size_hint_y: None
size_hint_x: 0.7
size: self.texture_size
pos_hint: {"x":0.6, "top":0.7}
markup: True
text_size: 700, None
valign: "middle"
halign: 'right'
padding_x: 5
ScrollView:
size_hint: (1, 1)
bar_width: 10
bar_color: 0.1, 0.1, 0.1, 0.1
bar_inactive_color: 0.15, 0.15, 0.15, 0.15
effect_cls: "ScrollEffect"
scroll_type: ['bars']
Label:
id: f_output2
text: "long text2 \n" * 100
size_hint_y: None
size_hint_x: 1
size: self.texture_size
pos_hint: {"x":0.6, "top":0.7}
text_size: 600, None
markup: True
解决方案
您可以制作一个并使用2 个标签ScrollView
创建一个GridLayout
cols:2
ScrollView:
size_hint: (1, 1)
bar_width: 10
bar_color: 0.1, 0.1, 0.1, 0.1
bar_inactive_color: 0.15, 0.15, 0.15, 0.15
effect_cls: "ScrollEffect"
scroll_type: ['bars']
GridLayout:
cols: 2
size_hint_y:None
height:self.minimum_height
Label:
id: f_output1
text: "long text1 \n" * 100
size_hint_y: None
size_hint_x: 0.7
size: self.texture_size
pos_hint: {"x":0.6, "top":0.7}
markup: True
text_size: 700, None
valign: "middle"
halign: 'right'
padding_x: 5
Label:
id: f_output2
text: "long text2 \n" * 100
size_hint_y: None
size_hint_x: 1
size: self.texture_size
pos_hint: {"x":0.6, "top":0.7}
text_size: 600, None
markup: True
推荐阅读
- angular - 如何将对象绑定到 Angular 中的选项值?
- android - Android后台任务选择
- regex - 如何检测 AND ( | ) 捕获组中没有空格,以十进制表示
- javascript - 在反应铬扩展中保留状态
- python-3.x - 检查天气文件仍在使用中
- ios - 隐藏和取消隐藏标签栏时管理视图框架
- git - 无法解决 BitBucket git 冲突
- angular - 将多个可观察对象的结果传递给对象
- react-native - React Native flex 和自定义组件布局问题
- excel - 当我在 vba 中保存 pdf 文件时,如何超越“导出为 pdf”对话框