Kivy Scatter、图像大小和位置的问题

Issues with Kivy Scatter, Image size and position

我在尝试将图像添加到 Kivy 中的 Scatter 时遇到了很多问题。我希望图像首先出现与 boxlayout 相同的高度。然后我希望能够移动和缩放它(目前确实有效)。当我 运行 代码时,图像显示得非常小。如果 window 的大小发生变化,我还希望图像能够自行调整大小。我是 kivy 的新手,所以任何帮助都会很棒。谢谢!

<MyGridLayout>:
rows: 1

BoxLayout:
    id:layout1
    orientation: 'vertical'

    BoxLayout:
        id: box1
        size_hint : [1,0.5]

        StencilView:
            ScatterLayout:
                center_x: box1.center_x
                center_y: box1.center_y

                Image:
                    source: 'histo_test.png'
                    size_hint_y: None
                    size_hint_x: None
                    width: self.parent.width
                    height: self.parent.width/self.image_ratio
                    center: self.parent.center
                    allow_stretch: True
                    keep_ratio: True




    BoxLayout:
        size_hint : [1,0.5]
        id:box2

        StencilView:
            ScatterLayout:
                center_x: box2.center_x
                center_y: box2.center_y

                Image:
                    source: 'flower.png'
                    size_hint_y: None
                    size_hint_x: None
                    width: self.parent.width
                    height: self.parent.width/self.image_ratio
                    center: self.parent.center
                    allow_stretch: True
                    keep_ratio: True

图片的大小必须是StencilView的大小,所以:

size: stencil.width, stencil.height

width: stencil.width
height: stencil.width/self.image_ratio

(stencil是StencilView的id)

并且ScatterLayout的大小必须是图片的大小:

size: my_image.size  

(my_image是图片的id)

您还可以使用 StencilView 的位置设置 ScatterLayout 的位置:

pos: stencil.pos

而不是这个:

center_x: box1.center_x    
center_y: box1.center_y

观看 this video 了解更多信息。


我写的这段代码几乎是一样的

<MyGridLayout>:
    orientation: 'vertical'
    StencilView:
        id: stencil1
        Scatter:
            pos: stencil1.pos
            size: my_image1.size
            Image:
                id: my_image1
                size: stencil1.width, stencil1.height
                source: 'dog.jpg'
                allow_stretch: True
                keep_ratio: False
    StencilView:
        id: stencil2
        Scatter:
            pos: stencil2.pos
            size: my_image2.size
            Image:
                id: my_image2
                size: stencil2.width, stencil2.height
                source: 'flower.jpg'
                allow_stretch: True
                keep_ratio: False

对不起,如果我的英语不清楚