2016-05-02 11 views
1

私の例では、番号のついたボードがあります。図は400x600の画面サイズで正しく表示されます。さまざまな画面サイズでウィジェットを中央につなぐ方法は?

enter image description here

しかし、あなたは1200x600に画面サイズを変更した場合、番号が長距離互いに離れるクリープ:

enter image description here

ここで私はそれ(cleanscreen.kv)どのように行うのです:

#:kivy 1.9.1 

<[email protected]> 
    text: root.button_text 
    size_hint_y: None 
    text_size: root.width - 150, root.height 
    valign: "middle" 
    height: 40 


<CleanScreen> 
    orientation: "vertical" 

    FloatLayout: 
     Image: 
      size_hint: .52, .52 
      pos_hint: {"center_x": .23, "y": .30} 
      allow_stretch: True 
      source: "6.png" 
     Image: 
      size_hint: .52, .52 
      pos_hint: {"center_x": .43, "y": .30} 
      allow_stretch: True 
      source: "5.png" 
     Image: 
      size_hint: .25, .25 
      pos_hint: {"center_x": .54, "y": .35} 
      allow_stretch: True 
      source: "dot.png" 
     Image: 
      size_hint: .52, .52 
      pos_hint: {"center_x": .65, "y": .30} 
      allow_stretch: True 
      source: "8.png" 
     Image: 
      size_hint: .18, .18 
      pos_hint: {"center_x": .80, "center_y": .75} 
      allow_stretch: True 
      source: "gb.png" 

ScrollView: 
    GridLayout: 
     id: gridlayout_ID 
     cols: 1 
     size_hint_y: None 
     padding: 10 
     height: self.minimum_height 
     canvas: 
      Color: 
       rgb: 1.0, 1.0, 1.0, 
      Rectangle: 
       pos: self.pos 
       size: self.size 

cleanscreen.py:

#! /usr/bin/python2.7 
# -*- coding: utf-8 -*- 

import kivy 
kivy.require("1.9.1") 

from kivy.app import App 
from kivy.uix.button import Button 
from kivy.uix.boxlayout import BoxLayout 
from kivy.lang import Builder 
from kivy.config import Config 
from kivy.properties import StringProperty 

Config.set("graphics", "width", "400") 
Config.set("graphics", "height", "600") 


class CustomButton(Button): 
    button_text = StringProperty("") 


class CleanScreen(BoxLayout): 
    Builder.load_file("cleanscreen.kv") 

    def __init__(self, **kvargs): 
     super(CleanScreen, self).__init__(**kvargs) 
     self.create_custom_button(self.ids.gridlayout_ID) 

    def create_custom_button(self, gridlayout_ID): 
     for i in range(50): 
      gridlayout_ID.add_widget(
       CustomButton(button_text="Button {}".format(i))) 

if __name__ in ["__main__", "__android__"]: 
    class Test(App): 
     def build(self): 
      return CleanScreen() 


    Test().run() 

数字を中心にどのように結び付けるか、それらの間の距離は常に異なる画面サイズで同じになっていますか?

答えて

1

BoxLayoutで数字の画像を入れてみてください、と途中でBoxLayout自体を配置します。

FloatLayout: 
    BoxLayout: 
     orientation: "horizontal" 
     #padding: play with this for better padding 
     pos_hint: {"center_x": .50, "y": .30} 
     Image: #I'm first 
     Image: #2nd 
     Image: #3rd 
     ... 
関連する問題