使用钛

时间:2016-03-14 07:51:29

标签: android iphone titanium

我有一个父视图3图像视图。我还有三个关闭按钮,用于从点击事件的父视图中删除相应的图像。我如何删除这些图像?我提供了示例代码。我尝试了我所知道的一切,并搜索了整个互联网,但没有找到任何东西。提前致谢。

var imageCount = 0;
var imageCloseButton = Titanium.UI.createView();

// bottom image view to display image preview
var bottomImageGallery = Titanium.UI.createView({
    width : '100%',
    height : 110,
    backgroundColor : '#000',
    opacity : 0.75,
    //backgroundColor: 'rgba(0,0,0,0.25)',
    bottom : 70,
    layout : 'horizontal'
});

var bottomImageGalleryOverlay = Titanium.UI.createView({
    width : '100%',
    height : 110,
    //zIndex : 999,
    //backgroundColor : '#000',
    opacity : 0,
    backgroundColor : 'transparent',
    bottom : 70,
    layout : 'horizontal'
});
//bottomImageGallery.add(bottomImageGalleryOverlay);
var bottomControls = Titanium.UI.createView({
    width : '100%',
    height : 70,
    backgroundColor : '#000',
    opacity : 1,
    //backgroundColor: 'rgba(0,0,0,0.25)',
    bottom : 0,
    //layout: 'horizontal'
});


//add controls to the view
    bottomControls.add(captureButton);
    bottomControls.add(saveButton);
    bottomControls.add(notesButton);
    bottomControls.add(galleryButton);

    var overlay = Titanium.UI.createView();
overlay.add(topView);
overlay.add(bottomControls);
overlay.add(bottomImageGallery);
//overlay.add(bottomImageGalleryOverlay);
captureButton.addEventListener('click', function() {
    if (imageCount < 3) {

        Ti.Media.takePicture();

        if (imageCount == 2) {
            captureButton.hide();
        }

    }

});

closeButton.addEventListener('click', function() {

    Ti.Media.hideCamera();
    imageCount = 0;

});
//show camera functions
Titanium.Media.showCamera({
    saveToPhotoGallery : false,
    success : function(event) {

        // place our picture into our window

        var imageView = Ti.UI.createImageView({
            image : event.media,
            id : imageCount + 3,
            //backgroundImage:event.media,
            //backgroundColor : '#000',
            //backgroundImage: event.media,
            left : 5,
            top : 5,
            opacity : 1,
            width : 100,
            height : 100,
            // bottom:62
        });

        imageCloseButton = Titanium.UI.createButton({
            top : 0,
            left : -25,
            id : imageCount,
            backgroundColor : 'transparent',
            width : 30,
            height : 30,
            font : {
                fontSize : 15,
                fontWeight : 'bold',
                fontFamily : 'Helvetica Neue',
                color : 'white'
            },
            title : 'X'
        });

        bottomImageGallery.add(imageView);
        bottomImageGallery.add(imageCloseButton);
        imageCount++;
    },
    cancel : function() {
    },
    error : function(error) {

    },
    overlay : overlay,
    showControls : false, // don't show system controls
    mediaTypes : Ti.Media.MEDIA_TYPE_PHOTO,
    autohide : false // tell the system not to auto-hide and we'll do it ourself
});

2 个答案:

答案 0 :(得分:0)

把它放在按钮点击事件....

ImageView.setImageDrawable(null);

答案 1 :(得分:0)

您是否尝试将此代码添加到成功回调中:

//show camera functions
Titanium.Media.showCamera({
    saveToPhotoGallery : false,
    success : function(event) {
    // place our picture into our window

    var imageView = Ti.UI.createImageView({
        image : event.media,
        id : imageCount + 3,
        //backgroundImage:event.media,
        //backgroundColor : '#000',
        //backgroundImage: event.media,
        left : 5,
        top : 5,
        opacity : 1,
        width : 100,
        height : 100,
        // bottom:62
    });

    imageCloseButton = Titanium.UI.createButton({
        top : 0,
        left : -25,
        id : imageCount,
        backgroundColor : 'transparent',
        width : 30,
        height : 30,
        font : {
            fontSize : 15,
            fontWeight : 'bold',
            fontFamily : 'Helvetica Neue',
            color : 'white'
        },
        title : 'X'
    });

    imageCloseButton.addEventListener('click', function(e){

       bottomImageGallery.remove(imageView);

    });

    bottomImageGallery.add(imageView);
    bottomImageGallery.add(imageCloseButton);
    imageCount++;
},
cancel : function() {
},
error : function(error) {

},
overlay : overlay,
showControls : false, // don't show system controls
mediaTypes : Ti.Media.MEDIA_TYPE_PHOTO,
    autohide : false // tell the system not to auto-hide and we'll do it ourself
});