在GridLayout

时间:2017-04-13 12:04:44

标签: kivy kivy-language rotatetransform

我正在使用kivy(1.9.1)编写应用程序,由于GridLayout(2 * 2),它分为4个小部件。我搜索两个上面的翻转180°。

我尝试用ScatterLayout做,但是细胞跳到右下角...... 我试图在一个小部件中插入Scatter,但我没有找到如何正确设置大小。

我读过使用以下代码来优化资源消耗:

        canvas.before:
            PushMatrix
            Rotate:
                angle: 180
                origin: self.center
        canvas.after:
            PopMatrix

乍一看它很有效,但遗憾的是,“触摸区域”没有旋转。

我发现的唯一两件事就是将ScatterLayout放在内部和AnchorLayout中,或者为每个孩子使用前面的代码......

我认为有一个更好的解决方案,但到目前为止我还没有找到它。

请查看下面我的.kv文件,了解我的实验内容:

GridLayout:
    cols: 2
    rows: 2

    AnchorLayout:
        ScatterLayout:
            center: self.parent.center
            do_rotation: False
            do_translation: False
            do_scale: False
            rotation: 180

            GridLayout:
                cols: 2
                Button:
                    text: '1.1'
                Button
                    text: '1.2'

     Button:
         text: '2'

     GridLayout:
         size: self.parent.size
         center: self.parent.center
         cols: 3

         Button:
             canvas.before:
                 PushMatrix
                 Rotate:
                     angle: 180
                     origin: self.center
            canvas.after:
                PopMatrix
            text: '3.1'

         Button:
             canvas.before:
                 PushMatrix
                 Rotate:
                     angle: 180
                     origin: self.center
             canvas.after:
                  PopMatrix
             text: '3.2'

        GridLayout:
            size: self.parent.size
            center: self.parent.center
            rows: 2

            canvas.before:
                PushMatrix
                Rotate:
                    angle: 180
                    origin: self.center
            canvas.after:
                PopMatrix

            Button:
                text: '3.3.1'
            Button:
                text: '3.3.2'

    Button:
        text: '4'

.py文件只不过是:

from kivy.app import App

class MainApp(App):
    pass

if __name__ == '__main__':
    MainApp().run()

提前致谢。

1 个答案:

答案 0 :(得分:0)

是的,您可以使用散点图。
试试这个:

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.lang import Builder


KV = '''

MyGrid:
    rows: 2
    cols: 2
    BoxLayout:
        id: w1
        Scatter:
            size: w1.size
            rotation: 180
            do_rotation: False
            Button:
                size: w1.size
                text: "Label1"

    BoxLayout:
        id: w2
        Scatter:
            size: w2.size
            rotation: 180
            do_rotation: False
            Button:
                size: w2.size
                text: "Label2"

    Button:
        text: "Label3"
    Button:
        text: "Label4"

'''



class MyGrid(GridLayout):
    pass


class MyApp(App):

    def build(self):
        return Builder.load_string(KV)


MyApp().run()