猕猴桃的布局。如何填充整个空间?

时间:2019-03-06 11:10:16

标签: kivy

我应该在下面的代码中进行哪些更改,以使RecycleView标签充满AddDone按钮之间的整个空间?我尝试了size_hint_x: None和许多其他方法。布局的工作方式很难理解...

from kivy.config import Config
Config.set('graphics', 'multisamples', '0')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.recycleboxlayout import RecycleBoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
from kivy.properties import ObjectProperty
kv = """
#:import FadeTransition kivy.uix.screenmanager.FadeTransition
ScreenManager:
    transition: FadeTransition()
    Requests:


<Main>

    materialType:     request_material.text
    materialLength:   materials_type_length_spinner.text
    materialsQuantity: materials_type_quantity_spinner.text

    BoxLayout:

        size_hint_y: None
        height: 25

        GridLayout:
            cols: 4
            #size_hint_x: None
            Spinner:
                id: request_material
                width: 60
                size_hint_x: None
                text: 'SC/SC'
                values: ['SC/SC','SC/LC', 'LC/LC', 'RJ45', 'ODF']
            Spinner:
                id: materials_type_length_spinner
                size_hint_x: None
                width: 25
                text: 'L'
                values: ['1','2','3','4','5','6','7','8','9','10','11','12']
            Spinner:
                id: materials_type_quantity_spinner
                size_hint_x: None
                width: 25
                text: 'Q'
                values: ['1','2','3','4','5','6','7','8','9','10','11','12']
            Button:
                size_hint_x: None
                width: 40
                text: "Add"
                on_press: root.add_materials()
        RecycleView:
            id: materials_recycle_view
            viewclass: 'Label'            
            SelectableRecycleBoxLayout:
                spacing: 15
                default_size: 100, dp(25)
                default_size_hint: None, None
                size_hint_y: None
                height: self.minimum_height
                orientation: 'horizontal'
        Button:
            size_hint_x: None
            width: 42
            text: "Done"


<Requests>
    Main:

"""
class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
                                 RecycleBoxLayout):
    pass

class Main(BoxLayout):

    materialType =     ObjectProperty()
    materialLength=    ObjectProperty()
    materialsQuantity= ObjectProperty()

    materialsTab = []

    def add_materials(self):

        material = self.materialType + " " + self.materialLength + "m " + self.materialsQuantity + "pcs"

        dict = {}
        dict.update({'text': material})

        self.materialsTab.append(dict)
        print(self.materialsTab)
        self.ids.materials_recycle_view.data = self.materialsTab
        print(self.materialsTab)

class Requests(Screen):
    pass

class ScreenManagement(ScreenManager):
    pass

sm = Builder.load_string(kv)

class TestApp(App):
    def build(self):
        return sm

if __name__ == '__main__':
    TestApp().run()

0 个答案:

没有答案