本文介绍了强制将Kivy小部件的方向设置为横向/纵向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个我希望ScreenManager的屏幕之一横向放置的应用程序.我不希望它本身变成垂直.到目前为止,我了解到的只有buildozer.spec文件可以更改应用程序的方向.我想要的是更改小部件的方向.有什么办法吗?
I'm developing an app where I want one of ScreenManager's screen to be in landscape orientation. I don't want it to change to vertical by itself. As of now, what I learned is only buildozer.spec file can change the app's orientation. What I want is to change the widget's orientation. Is there any way to do this?
推荐答案
您可以将屏幕内容放在分散的布局上,然后旋转它:
You can place a content of the screen on a scatter layout, and then rotate it:
test.kv:
ScreenManager:
Screen:
name: 'normal'
Grid
Screen:
name: 'flipped'
ScatterLayout:
do_rotation: False
do_scale: False
do_translation: False
rotation: 90
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
size_hint: None, None
size: root.height, root.width
Grid
<Grid@GridLayout>:
cols: 1
Button:
text: 'normal'
on_press: app.root.current = 'normal'
Button:
text: 'flipped'
on_press: app.root.current = 'flipped'
main.py:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from kivy.app import App
class Test(App):
pass
Test().run()
@edit还有plyer的 Orientation .
@editThere is also plyer's Orientation.
这篇关于强制将Kivy小部件的方向设置为横向/纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!