本文介紹了如何在 Kivy ScrollView 中滾動 GridLayout?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
目前這是我無法滾動的 kv 代碼:
At the moment this is my kv code that is not scrollable:
BoxLayout:
id: bl
orientation: 'vertical'
padding: 10, 10
row_default_height: '48dp'
row_force_default: True
spacing: 10, 10
GridLayout:
id: layout_content
cols: 1
row_default_height: '20dp'
row_force_default: True
spacing: 0, 0
padding: 0, 0
Label:
text: 'You don''t have any downloads. Please add new download from Home screen'
如何讓上面的 kv 代碼可滾動?我知道 Kivy ScrollView 只接受一個孩子,而且我已經讓 GridLayout 成為新 ScrollView 的孩子.但它不起作用.有什么建議嗎?
How do you make the above kv code scrollable? I know that Kivy ScrollView only accept one child, and I have already make GridLayout to be child of a new ScrollView. But it's not working. Any suggestion?
推薦答案
根據ScrollView 的文檔 您必須至少禁用 ScrollView 的子 size_hint 之一:
According to the documentation for ScrollView you have to disable at least one of the ScrollView's child size_hint:
<Controller>:
layout_content: layout_content
BoxLayout:
id: bl
orientation: 'vertical'
padding: 10, 10
row_default_height: '48dp'
row_force_default: True
spacing: 10, 10
ScrollView:
size: self.size
GridLayout:
id: layout_content
size_hint_y: None
cols: 1
row_default_height: '20dp'
row_force_default: True
spacing: 0, 0
padding: 0, 0
Label:
text: "Lorem ipsum dolor sit amet"
并綁定布局的大小以適應自身:
And bind the layout's size to adapt itself:
# main.py
class Controller(FloatLayout):
layout_content=ObjectProperty(None)
def __init__(self, **kwargs):
super(Controller, self).__init__(**kwargs)
self.layout_content.bind(minimum_height=self.layout_content.setter('height'))
這篇關于如何在 Kivy ScrollView 中滾動 GridLayout?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!