1

在我的示例中,有带有数字的板。数字在 400x600 的屏幕尺寸上正确显示。

在此处输入图像描述

但如果将屏幕尺寸更改为 1200x600,数字会在很长的距离内相互远离:

在此处输入图像描述

这是我的做法(cleanscreen.kv):

#:kivy 1.9.1

<CustomButton@Button>
    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

清洁屏幕.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()

如何将数字绑在中心,它们之间的距离在不同的屏幕尺寸上总是相同的?

4

1 回答 1

1

尝试将数字图像放在 aBoxLayout中,并将其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
        ...
于 2016-05-02T08:13:41.863 回答