Forcing a Kivy widget's orientation to be landscape/portrait

笑着哭i 提交于 2019-12-12 03:29:13

问题


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?


回答1:


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 There is also plyer's Orientation.



来源:https://stackoverflow.com/questions/36639430/forcing-a-kivy-widgets-orientation-to-be-landscape-portrait

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!