无法将Kivy Scatter小部件添加到轮播中

时间:2015-04-05 05:40:21

标签: android kivy

我正在尝试创建一个轮播,其中每个图像都添加到Scatter或ScatterLayout,然后再添加到轮播中。我想用触摸手势调整图像大小。该应用程序适用于Android手机。

但是,我收到错误,我无法添加散点小部件,因为它已经有父级。

Cannot add <kivy.uix.scatter.ScatterLayout object at 0x7fb9b903def0>, 
it already    has a parent kivy.uix.relativelayout.RelativeLayout
object at 0x7fb9b8e21530>.

我可以将一个图像添加到散点小部件中并展开。但是对于多个图像,当我尝试在轮播和图像之间插入散点图或散布图时,会产生错误。

如有必要,用户需要在每个轮播页面上拉伸图像(放大)。

import kivy
kivy.require('1.8.0')

from kivy.app import App
from kivy.uix.carousel import Carousel
from kivy.uix.scatter import Scatter
from kivy.uix.scatterlayout import ScatterLayout
from kivy.uix.scatter import ScatterPlane
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.image import Image
from kivy.uix.image import AsyncImage
from kivy.uix.anchorlayout import AnchorLayout

one_image = False
scatter = ScatterLayout(do_rotation=False)
carousel = Carousel(direction='right', loop=True)
data_dir_receipt = 'data/receipts'
prefix = '02_february_2015_receipts-all-*'
    if one_image is True:
        prefix = '02_february_2015_receipts-all-1.png'
        filename = join(data_dir_receipt, prefix)
        image = AsyncImage(source=filename, allow_stretch=True)
        scatter.add_widget(image)
        return scatter
    else:
        for filename in glob(join(data_dir_receipt, prefix)):
            image = AsyncImage(source=filename, allow_stretch=True)
            scatter.add_widget(image)
            carousel.add_widget(scatter)
        return carousel

0 个答案:

没有答案