Kivy Scrollview Boxlayouts друг на друга - PullRequest
0 голосов
/ 08 ноября 2019

мой код, как показано ниже. Я использую scrollview, чтобы сделать мой экран прокручиваемым. Работает нормально с наполнителями. Тем не менее, мои boxlayouts друг на друга. Я возился с size_hint_y, но не повезло. Что я тут не так сделал? Все, что мне нужно, это метка и ввод текста на отдельной строке в качестве строк-заполнителей.

from kivy.uix.gridlayout import GridLayout
from kivy.uix.scrollview import ScrollView
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.button import Button
from kivy.lang import Builder

KV = '''
<MyLabel@Label>:
    size_hint:1,None

<ExampleScreen>:
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'title'
            size_hint_y: .0625
        ScrollView:
            size_hint: 1,.2
            BoxLayout:
                size_hint: 1,None
                height: self.minimum_height
                cols: 1

                GridLayout:
                    size_hint: 1,None
                    height: self.minimum_height
                    cols: 1
                    rows: 8                    

                    BoxLayout:                             
                        size_hint_y:.125
                        height: self.minimum_height                   
                        Label:                              
                            size_hint_x:40
                            text: "Name of item: "                                

                        TextInput:                                
                            size_hint_x:60                                                               
                            hint_text: 'Name of the item'

                    BoxLayout:                        
                        size_hint_y:.125
                        height:self.minimum_height
                        Label:                    
                            size_hint_x:40
                            text: "Description: "

                        TextInput:                                                     
                            size_hint_x:60                        
                            hint_text: 'Description of the item'



                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel: 
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'
                    MyLabel:
                        text: 'Filler'

        BoxLayout:
            height: "60dp"
            size_hint_y:None
            Button:
                text: "Back"                
                on_release:
                    root.manager.transition.direction = "right"
                    root.back()


            Button:
                text: "Attach an image"                
                on_release:
                    root.manager.transition.direction = "right"
                    root.attachanimage()

            Button:
                text: "Submit"
                on_press:
                    app.get_running_app().display_loading_screen()
                on_release:
                    root.manager.transition.direction = "left"                    
                    root.submit()                

'''

class ExampleScreen(Screen):
    pass

kv = Builder.load_string(KV)

sm = ScreenManager()

sm.add_widget(ExampleScreen(name = 'example'))

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

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

1 Ответ

1 голос
/ 08 ноября 2019

Я думаю, проблема в том, что вам нужно установить height из Labels или TextInputs, которые находятся в BoxLayouts. Мое решение состоит в том, чтобы установить размер Labels и установить size_hint_y для BoxLayouts на None:

                BoxLayout:                             
                    size_hint_y: None
                    height: self.minimum_height                   
                    Label:  
                        size_hint_x:40
                        size_hint_y: None
                        height: self.texture_size[1] + 10
                        text: "Name of item: "                                

                    TextInput:
                        size_hint_x:60                                                               
                        hint_text: 'Name of the item'

                BoxLayout:  
                    size_hint_y: None
                    height:self.minimum_height
                    Label: 
                        size_hint_x:40
                        size_hint_y: None
                        height: self.texture_size[1] + 10
                        text: "Description: "

                    TextInput:  
                        size_hint_x:60                        
                        hint_text: 'Description of the item'

Как правило, вам необходимо установить соответствующий size_hint на None, чтобы size, width или height имели эффект. Вы можете опустить height: для Labels, но Label, похоже, использует больше высоты, чем необходимо. Также подумайте, нужно ли вашему TextInputs более одной строки.

...