Kivy - KivyMD ScrollView不会滚动和放大文本,从顶部从框架中走出的越多



我正在尝试用Kivy和KivyMD在python中制作一个应用程序,使用户可以从待办事项列表中查看他们的任务,并点击任务查看它们的详细信息;如截止日期、任务名称和任务描述。如果任务描述太长,我希望它滚动。但由于某种原因,随着文本变大,ScrollView中的文本首先从顶部移出框架,然后从底部移出。它实际上让我可以执行滚动功能,但它并没有滚动,而是表现得好像我没有任何空间滚动,然后弹回到它的初始位置。我还将ScrollView与MDList一起用于任务列表,到目前为止,它似乎运行良好。

  • Python版本3.10.4
  • Kivy 2.1.0版
  • KivyMD版本0.104.2

我试着用滚动视图制作一个测试应用程序,看看问题是否仍然存在。确实如此。以下是测试应用程序:

主.py

from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
class MainApp(MDApp):
def build(self):
return Builder.load_file('main.kv')
class WindowManager(ScreenManager):
pass
class TestWindow(Screen):
pass
if __name__ == "__main__":
MainApp().run()

main.kv

#: include testwindow.kv
WindowManager:
TestWindow:

测试窗口.kv

<TestWindow>:
name: "testwin"
Screen:
ScrollView:
do_scroll_x: False
size_hint: 1, 1
pos_hint: {"center_x": 0.5, "center_y": 0.5}
MDLabel:
id: scrollabel
text: "Computer programming is the process of performing a particular computation (or more generally, accomplishing a specific computing result), usually by designing and building an executable computer program. Programming involves tasks such as analysis, generating algorithms, profiling algorithms' accuracy and resource consumption, and the implementation of algorithms (usually in a chosen programming language, commonly referred to as coding). The source code of a program is written in one or more languages that are intelligible to programmers, rather than machine code, which is directly executed by the central processing unit. The purpose of programming is to find a sequence of instructions that will automate the performance of a task (which can be as complex as an operating system) on a computer, often for solving a given problem. Proficient programming thus usually requires expertise in several different subjects, including knowledge of the application domain, specialized algorithms, and formal logic."
text_size: self.height, None
font_size: 16
halign: 'left'
size_hint_y: None

为了启用文本的垂直滚动,您需要绑定道具。MDLabelheight到其纹理高度,也不修改其text_size

MDLabel:
id: scrollabel
text: "Computer programming is the process...formal logic."
size_hint_y: None
height: self.texture_size[1]
#                text_size: self.height, None
font_size: 16
halign: 'left'

最新更新