我如何定位和大小我的图像按钮

问题描述 投票:0回答:1

我是新来kivy,我要创建我的Android应用程序基本的UI,我想下面的代码的时候,我首先要创建我的BoxLayout我的UI分为三个部分:标题部分,主体部分和图标部分,其实我问题是如何的大小和位置我的图标图像按钮

<MyLabel@Label>:
    color: .8, .9, 0, 1
    font_size: 32
    text_size: self.width, None
    size_hint_y: None
    height: self.texture_size[1]

<MyBoxLayout>:    
    orientation: 'vertical'
    BoxLayout:
        size_hint: 1, .1
        Label:
            text: "Face-Reg"
            font_size: 50
            color: .8, .9, 0, 1
            text_size: self.size
    ScrollView:
        size_hint: 1, .8
        MyLabel:
            text: str ('Hello This is My  New Project ' * 100)

    BoxLayout:
        size_hint: 1, .1
        Button:
            size_hint_x: 0.25
            Image:
                source: 'icon/server.png'
                size:self.texture_size
        Button:
            size_hint_x: 0.25
            Image:
                source: 'icon/add.png'
                size:self.texture_size
        Button:
            size_hint_x: 0.25
            Image:
                source: 'icon/recog.png'
                size:self.texture_size
        Button:
            size_hint_x: 0.25
            Image:
                source: 'icon/renew.png'
                size:self.texture_size

输出屏幕快照:1四个图标重叠在一起,也大小不匹配按钮的大小如何解决呢?谢谢

python kivy
1个回答
0
投票

您可以调整size和使用pos的那些属性Image。例如,这里是你会如何调整第三Button

    Button:
        id: b3
        size_hint_x: 0.25
        Image:
            source: 'icon/recog.png'
            allow_stretch: True
            keep_ratio: False
            size: b3.size
            pos: b3.pos

注意分配给idButton。这id用于分配相同的大小和位置的Image。所述allow_stretch: True属性使得Image拉伸以适合指定sizekeep_ratio: False允许图像被不均匀地拉伸。详情请参见该Image documentation

© www.soinside.com 2019 - 2024. All rights reserved.