Android 在Tianium中使用id删除子视图

Android 在Tianium中使用id删除子视图,android,iphone,titanium,Android,Iphone,Titanium,我有一个父视图和它的3个图像视图。我还有三个关闭按钮,用于在单击事件时从父视图中删除相应的图像。如何删除这些图像?我已经提供了我的示例代码。我尝试了我所知道的一切,搜索了整个互联网,但什么也没找到。提前谢谢 var imageCount = 0; var imageCloseButton = Titanium.UI.createView(); // bottom image view to display image preview var bottomImageGallery = Titan

我有一个父视图和它的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
});
var-imageCount=0;
var imageCloseButton=tianium.UI.createView();
//用于显示图像预览的底部图像视图
var bottomImageGallery=tianium.UI.createView({
宽度:“100%”,
身高:110,
背景颜色:“#000”,
不透明度:0.75,
//背景颜色:“rgba(0,0,0,0.25)”,
底数:70,
布局:“水平”
});
var bottomImageGalleryOverlay=Titanium.UI.createView({
宽度:“100%”,
身高:110,
//zIndex:999,
//背景颜色:“#000”,
不透明度:0,
背景色:“透明”,
底数:70,
布局:“水平”
});
//添加(bottomImageGalleryOverlay);
var bottomControls=tianium.UI.createView({
宽度:“100%”,
身高:70,
背景颜色:“#000”,
不透明度:1,
//背景颜色:“rgba(0,0,0,0.25)”,
底部:0,
//布局:“水平”
});
//将控件添加到视图中
添加(captureButton);
添加(保存按钮);
底部控件。添加(notesButton);
底部控件。添加(galleryButton);
var overlay=tianium.UI.createView();
叠加。添加(俯视图);
叠加。添加(底部控件);
叠加。添加(bottomImageGallery);
//叠加。添加(bottomImageGalleryOverlay);
captureButton.addEventListener('click',function(){
如果(imageCount<3){
Ti.Media.takePicture();
如果(imageCount==2){
captureButton.hide();
}
}
});
closeButton.addEventListener('单击',函数()){
Ti.Media.hideCamera();
imageCount=0;
});
//显示摄像机功能
钛合金.媒体.展示照相机({
saveToPhotoGallery:false,
成功:功能(事件){
//把我们的照片放进我们的窗口
var imageView=Ti.UI.createImageView({
图片:event.media,
id:imageCount+3,
//背景图片:event.media,
//背景颜色:“#000”,
//背景图片:event.media,
左:5,,
前五名,
不透明度:1,
宽度:100,
身高:100,
//底数:62
});
imageCloseButton=Titanium.UI.createButton({
排名:0,
左:-25,
id:imageCount,
背景色:“透明”,
宽度:30,
身高:30,
字体:{
尺寸:15,
fontWeight:'粗体',
fontFamily:“Helvetica Neue”,
颜色:“白色”
},
标题:“X”
});
添加(imageView);
添加(imageCloseButton);
imageCount++;
},
取消:函数(){
},
错误:函数(错误){
},
叠加:叠加,
showControls:false,//不显示系统控件
媒体类型:Ti.Media.Media\u TYPE\u PHOTO,
autohide:false//告诉系统不要自动隐藏,我们会自己做
});

将此按钮置于“单击事件”按钮上

ImageView.setImageDrawable(null);

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

//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
});

显示您的努力和代码。添加您的代码您所尝试的可能会删除所有图像视图。我只想一次删除一个?在您添加的每个
imageView
上都会添加
click
事件。因此,它删除一个
ImageView
,然后单击
imageCloseButton
它只删除最后一个图像视图