代码之家  ›  专栏  ›  技术社区  ›  jrx3ctl

Kivy散射、图像大小和位置问题

  •  0
  • jrx3ctl  · 技术社区  · 7 年前

    <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
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   favcau    7 年前

    图像的大小必须是StencilView的大小,因此:

    size: stencil.width, stencil.height
    

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

    (模具是模具视图的id)

    size: my_image.size  
    

    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
    

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