【问题标题】:Kivy - Bottom and right position widget and margimKivy - 底部和右侧位置小部件和边距
【发布时间】:2017-05-30 14:14:35
【问题描述】:

我正在尝试将小部件放在底部和右侧位置,边距为 16dp,但是我尝试了多种方式,有多种布局,但它不起作用。有人可以帮帮我吗?

ex35.py

from kivy.app import App
from kivy.core.window import Window
Window.clearcolor = (1, 1, 1, 1)

class Ex35(App):
    pass

Ex35().run()

ex35.kv

FloatLayout:
    BoxLayout:
        orientation:'vertical'
        Button:
            text:'Hello'
        Button:
            text:'Hello'
        Button:
            text:'Hello'
        Button:
            text:'Hello'
        Button:
            text:'Hello'
        Button:
            text:'Hello'
        Button:
            text:'Hello'
        Button:
            text:'Hello'

    Widget:
        id: ellipse
        size_hint: (None, None)
        size: (dp(56), dp(56))
        canvas:
            Color:
                rgba: 0, 1, 0, 1
            Ellipse:
                size: self.size

【问题讨论】:

  • 你试过pos_hint吗? 16dp的边距到底是什么意思?像从右下角各 16dp 的空间?
  • Margim 16dp 我通过在 Ellipse 中添加 pos: (dp(16), dp(16)) 得到它。我没有得到的是把椭圆放在底部的右边

标签: python kivy kivy-language


【解决方案1】:

我用下面的代码得到了它:

FloatLayout:
    BoxLayout:
        orientation:'vertical'
        Button:
            text:'Hello'
        Button:
            text:'Hello'
        Button:
            text:'Hello'
        Button:
            text:'Hello'
        Button:
            text:'Hello'
        Button:
            text:'Hello'
        Button:
            text:'Hello'
        Button:
            text:'Hello'

    Widget:
        id: ellipse
        size_hint: (None, None)
        size: (dp(56), dp(56))
        pos_hint:{'right': 1}
        canvas.before:
            Color:
                rgba: 0, 1, 0, 1
            Ellipse:
                size: self.size
                pos: [dp(self.pos[0]) - dp(16), dp(self.pos[1]) + dp(16)]

【讨论】:

    猜你喜欢
    • 2015-09-15
    • 1970-01-01
    • 1970-01-01
    • 2015-12-30
    • 2018-12-24
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 2014-07-10
    相关资源
    最近更新 更多