2017-07-17 6 views
1

この私のアプリScrollview

<myAppLayout>  
    canvas.before: 
     Color: 
      rgba:1, 1, 1,1 
     Rectangle: 
      pos: self.pos 
      size: self.size 

    ScrollView: 
     size: self.size 
     size_hint: (None, None) 
     GridLayout: 
      cols:1  

      TextInput:  

       pos_hint:{"center_x":0.5,"y":0.1} 
       color:0,0.5,1,1 
       background_color:0,0.5,1,1 
       size:20,20   


      Label: 
       color:1,0,1,1 
       text:"hello" 
       text_size:self.size 
      Label: 
       color:1,0,1,1 
       text:"hello" 
       text_size:self.size 
      Label: 
       color:1,0,1,1 
       text:"hello" 
       text_size:self.size 
      Label: 
       color:1,0,1,1 
       text:"hello" 
       text_size:self.size 
      Label: 
       color:1,0,1,1 
       text:"hello" 
       text_size:self.size 
      Label: 
       color:1,0,1,1 
       text:"hello" 
       text_size:self.size 
      Label: 
       color:1,0,1,1 
       text:"hello" 
       text_size:self.size 
      Label: 
       color:1,0,1,1 
       text:"hello" 
       text_size:self.size 
      Label: 
       color:1,0,1,1 
       text:"hello" 
       text_size:self.size 
      Label: 
       color:1,0,1,1 
       text:"hello" 
       text_size:self.size 
      Label: 
       color:1,0,1,1 
       text:"hello" 
       text_size:self.size 
      Label: 
       color:1,0,1,1 
       text:"hello" 
       text_size:self.size 

PythonコードのためのKVファイルがこの

class myAppLayout(GridLayout): 
    pass 

のように見えている問題は、私の出力は、この(左下隅)のようないくつかのことを見ているのに対し、私は、デバイスのサイズに応じてラインごとに並べることを望みます enter image description here

答えて

1

ScrollViewのコンテンツをすべて利用するにはあなたが行うことができないことができスペース:一方

size: self.size 
size_hint: (None, None) 

は、ScrollView内のウィジェットが定義された高さ(size_hint_y =なし)を持っている必要がありますまたは、それらは自動的にScrollViewのサイズにそのサイズを調整します。

colsまたはrowsを指定しない場合、GridLayoutは例外をスローします。 myAppLayoutにはいくつかの行または列を割り当てる必要があります。

from kivy.app import App 
from kivy.uix.gridlayout import GridLayout 
from kivy.lang import Builder 

kv_text = ''' 

<[email protected]>: 
    color:1,0,1,1 
    text:"hello" 
    text_size:self.size 
    size_hint_y:None 
    height: 20 

<myAppLayout> 
    cols: 1 
    canvas.before: 
     Color: 
      rgba:1, 1, 1,1 
     Rectangle: 
      pos: root.pos 
      size: root.size 

    ScrollView: 
     GridLayout: 
      cols:1 
      size_hint_y: None 
      height: self.minimum_height 

      TextInput:  
       pos_hint:{"center_x":0.5,"y":0.1} 
       color:0,0.5,1,1 
       background_color:0,0.5,1,1 
       size_hint_y: None 
       height: 30   

      MyLabel: 
      MyLabel: 
      MyLabel: 
      MyLabel: 
      MyLabel: 
      MyLabel: 
      MyLabel: 
      MyLabel: 
      MyLabel: 
      MyLabel: 
      MyLabel: 
      MyLabel: 

''' 

class myAppLayout(GridLayout): 
    pass 

class MyApp(App): 
    def build(self): 
     return myAppLayout() 

def main(): 
    Builder.load_string(kv_text) 
    app = MyApp() 
    app.run() 

if __name__ == '__main__': 
    main() 

出力:

enter image description here

+0

私はkivyに新しいですし、ウェブサイトからの例を試してみることを新しいdidntのと説明をありがとうございました – Eka