【发布时间】:2013-12-25 22:55:57
【问题描述】:
跟进我询问的有关背景画布here 的问题,为了制作描述here 的嵌套布局,我有一个AnchorLayout 背景,我在该背景上嵌套了一个相对布局,以围绕固定大小的内部形成边距漂浮。
但是,我的嵌套小部件不在我的 AnchorLayout 内居中,尽管这既是用于锚布局的 default behavior,也被明确声明。为什么会这样?我的代码在这里:
#!/usr/bin/kivy
import kivy
kivy.require('1.7.2')
from random import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.graphics import Color, Ellipse, Rectangle
class MinimalApp(App):
title = 'My App'
def build(self):
root = RootLayout()
return(root)
class RootLayout(AnchorLayout):
pass
class Junk(RelativeLayout):
pass
if __name__ == '__main__':
MinimalApp().run()
还有kv文件:
#:kivy 1.7.2
#:import kivy kivy
<RootLayout>:
anchor_x: 'center' # I think this /is/ centered
anchor_y: 'center'
canvas.before:
Color:
rgba: 0.4, 0.4, 0.4, 1
Rectangle:
pos: self.pos
size: self.size
Junk:
anchor_x: 'center' # this is /not/ centered.
anchor_y: 'center'
Label:
text: unicode(self.center) # this /is/ appearing
color: 1,0,1,1
canvas.before:
Color:
rgba: 0.94, 0.94, 0.94, 1
Rectangle:
size: 400,400 # this is /not/ centered
Label:
text: unicode(self.size) # this is /not/ appearing
color: 1,0,0,1
【问题讨论】:
标签: python layout user-interface kivy