Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';在Android中,当滚动视图中的视图触发事件时,不能滚动滚动视图_Android_Drag And Drop_Scrollview_Titanium Mobile - Fatal编程技术网

Can';在Android中,当滚动视图中的视图触发事件时,不能滚动滚动视图

Can';在Android中,当滚动视图中的视图触发事件时,不能滚动滚动视图,android,drag-and-drop,scrollview,titanium-mobile,Android,Drag And Drop,Scrollview,Titanium Mobile,我正在使用Tianium SDK 3.1.1,我的应用程序中的逻辑如下: 我有一个类似于TableView的ScrollView,其中包含用作分区的视图,每个分区都包含可拖动视图,每个水平拖动视图都有一个touchstart,touchmove和touchend事件来拖动它们。问题是,如果我将ScrollView的属性canCancelEvents设置为false,则无法滚动ScrollView。这个问题在iOS中不会发生,只有在Android中才会发生 我尝试将Android的canCance

我正在使用Tianium SDK 3.1.1,我的应用程序中的逻辑如下:

我有一个类似于TableView的ScrollView,其中包含用作分区的视图,每个分区都包含可拖动视图,每个水平拖动视图都有一个
touchstart
touchmove
touchend
事件来拖动它们。问题是,如果我将ScrollView的属性
canCancelEvents
设置为false,则无法滚动ScrollView。这个问题在iOS中不会发生,只有在Android中才会发生

我尝试将Android的
canCancelEvents
属性设置为true,但是当滚动工作时,当我拖动滚动视图中的一个视图时,如果我有机会垂直拖动它(可拖动视图不会垂直拖动,只会水平拖动)然后ScrollView的scroll事件控制事件,拖动被中断。 这是我的代码:

// This function create a horizontal draggable View
function evaluationItem(item)
{
    var self = Ti.UI.createView({
        width:Ti.Platform.displayCaps.platformWidth, 
        height:88 + dpi
    });

    var backgroundWorkspace = Ti.UI.createView({
        top:0 + dpi, 
        left:0 + dpi, 
        backgroundColor:"#404040", 
        width:Ti.Platform.displayCaps.platformWidth, 
        height:'100%', 
        zIndex:0
    });

    var checkEvaluation = Ti.UI.createImageView({
        image:imagesPath + "CheckEvaluation.png", 
        opacity:0, 
        left:20 + dpi
    });

    var notYetEvaluation  = Ti.UI.createImageView({
        image:imagesPath + "NotYetEvaluation.png", 
        opacity:0, 
        right:20 + dpi
    });

    backgroundWorkspace.add(checkEvaluation);
    backgroundWorkspace.add(notYetEvaluation);

    var foregroundWorkspace = Ti.UI.createView({
        top:0 + dpi, 
        left:0 + dpi, 
        backgroundColor:"#FFFFFF", 
        width:Ti.Platform.displayCaps.platformWidth, 
        height:'100%', 
        zIndex:1
    });

    var foregroundWorkspaceDraggable = Ti.UI.createView({
        top:0 + dpi, 
        left:0 + dpi, 
        backgroundColor:"transparent", 
        width:Ti.Platform.displayCaps.platformWidth, 
        height:'100%', 
        zIndex:2
    });

    var curX, curY;
    var deltaX, deltaY;
    var currentPositionX, currentPositionY;
    var initialViewX = parseInt(foregroundWorkspace.getLeft()) , initialViewY = parseInt(foregroundWorkspace.getTop());
    var limitToTheRight = Ti.Platform.displayCaps.platformWidth/2.5;
    var limitToTheLeft = (-1)* Ti.Platform.displayCaps.platformWidth/2.5;   
    var neutralColor = "#404040";
    var positiveColor = "#79b715";
    var negativeColor = "#9e9e9e";

    // event for touchstart
    foregroundWorkspaceDraggable.addEventListener('touchstart', function(e) {
        curX = e.x;
        curY = e.y; 
});

    var hoveringOver = 0;
    // event for touchmove, this handles the dragging
    foregroundWorkspaceDraggable.addEventListener('touchmove', function(e) {

        var currentOpacity = currentPositionX / limitToTheRight;
        if(currentOpacity < 0)
            currentOpacity = 0;
        else if(currentOpacity > 1)
            currentOpacity = 1;
        checkEvaluation.setOpacity(currentOpacity);

        var currentOpacityNotYet = currentPositionX / limitToTheLeft;
        if(currentOpacityNotYet < 0)
            currentOpacityNotYet = 0;
        else if(currentOpacityNotYet > 1)
            currentOpacityNotYet = 1;
        notYetEvaluation.setOpacity(currentOpacityNotYet);

        deltaX = e.x - curX;
        currentPositionX = initialViewX + deltaX;

        if (currentPositionX > limitToTheRight) {
            if (hoveringOver != 1) {
                hoveringOver = 1;
                backgroundWorkspace.animate({
                    backgroundColor : positiveColor,
                    duration : 250
                });
            }
        } else if (currentPositionX <= limitToTheLeft) {
            if (hoveringOver != -1) {
                hoveringOver = -1;
                backgroundWorkspace.animate({
                    backgroundColor : negativeColor,
                    duration : 250
                });
            }
        } else {
            if (hoveringOver != 0) {
                hoveringOver = 0;
                backgroundWorkspace.animate({
                    backgroundColor : neutralColor,
                    duration : 250
                });
            }
        }
        foregroundWorkspace.setLeft(currentPositionX);
    });

    function recallControl()
    {
        foregroundWorkspace.animate({
            left : 0 + dpi,
            duration : 500
        });
    }

    // event for touchend, this handles where the view remains in the end
    foregroundWorkspaceDraggable.addEventListener("touchend", function(e){
        if (currentPositionX > limitToTheRight) {
            foregroundWorkspace.animate({
                left : Ti.Platform.displayCaps.platformWidth + dpi,
                duration : 500
            }, function() {
                self.animate({
                    height : 0 + dpi,
                    duration : 500
                });
            }); 
        } else if (currentPositionX <= limitToTheLeft) {
            foregroundWorkspace.animate({
                left : -Ti.Platform.displayCaps.platformWidth + dpi,
                duration : 500
            });
        } else {
            // alert('3');

            recallControl();
        }


    });

    var foregroundWorkspaceDecorator = Ti.UI.createView({
        width:Ti.UI.FILL, 
        height:1 + dpi, 
        backgroundColor:"#d8d8d8", 
        bottom:0 + dpi, 
        left:0 + dpi
    });

    foregroundWorkspace.add(foregroundWorkspaceDecorator);

    var evaluationIdView = Ti.UI.createView({
        width:20 + dpi, 
        height:'100%', 
        top:0 + dpi, 
        left:10 + dpi, 
        backgroundColor:"transparent"
    });

    var evaluationIdLabel = Ti.UI.createLabel({
        text : item.id + ".",
        font : {
            fontSize : 20 + dpi,
            fontWeight : "bold"
        },
        color : item.color
    });

    evaluationIdView.add(evaluationIdLabel);

    foregroundWorkspace.add(evaluationIdView);

    var evaluationContentLabel = Ti.UI.createLabel({
        text : "This is an evaluation,you can drag to the left or to the right and it will evaluate your kid",
        left : 40 + dpi,
        width : Ti.UI.FILL,
        right : 30 + dpi,
        font : {
            fontSize : 14 + dpi
        },
        color : "#7a7a7a"
    });

    foregroundWorkspace.add(evaluationContentLabel);

    self.add(backgroundWorkspace);
    self.add(foregroundWorkspace);
    self.add(foregroundWorkspaceDraggable);

    return self;    
}

// function that creates the sections for the ScrollView
function evaluationCategory(category)
{
    var backgroundColor = "#229ce5";

    switch(category.categoryType)
    {
        case 0: // blue
            backgroundColor = "#229ce5";
            break;
        case 1: // pink
            backgroundColor = "#c13a78";
            break;
        case 2: // orange
            backgroundColor = "#f87739";
            break;
        case 3: // green
            backgroundColor = "#79b715";            
            break;      
        case 4: // yellow
            backgroundColor = "#ffd024";            
            break;      
    }
    var self = Ti.UI.createView({
        height:Ti.UI.SIZE, 
        layout:"vertical"
    });

    var titleView = Ti.UI.createView({
        width:Ti.UI.FILL, 
        height:60 + dpi, 
        backgroundColor:backgroundColor
    });

    var titleViewLabel = Ti.UI.createLabel({
        text : "physical",
        font : {
            fontSize : 20 + dpi,
            fontWeight : "bold"
        },
        color : "#FFFFFF",
        textAlign : "left",
        width : Ti.UI.SIZE,
        height : Ti.UI.SIZE,
        left : 10 + dpi
    });

    titleView.add(titleViewLabel);

    self.add(titleView);

    var workspace = Ti.UI.createView({
        width:Ti.UI.FILL, 
        height:Ti.UI.SIZE,
        layout:"vertical"
    });

    for (var i = 0; i < 5; i++) {
        workspace.add(evaluationItem({
            id : i,
            color : backgroundColor
        }));
    }

    self.add(workspace);

    return self;
}
    // my ScrollView
    if(osname === 'android'){
        cancelEvents = true;
    }
    var scrollview = Ti.UI.createScrollView({
        top : 0,
        left : 0,
        contentHeight : Ti.UI.SIZE,
        scrollType : 'vertical',
        layout : 'vertical',
        showVerticalScrollIndicator : true,
        canCancelEvents:cancelEvents,
    });

    scrollview.add(evaluationCategory({
        categoryType : 0
    }));
    scrollview.add(evaluationCategory({
        categoryType : 1
    }));
    scrollview.add(evaluationCategory({
        categoryType : 2
    }));
    scrollview.add(evaluationCategory({
        categoryType : 3
    }));
//此函数用于创建水平可拖动视图
功能评估项目(项目)
{
var self=Ti.UI.createView({
宽度:Ti.Platform.displayCaps.platformWidth,
高度:88+dpi
});
var backgroundWorkspace=Ti.UI.createView({
顶部:0+dpi,
左:0+dpi,
背景色:“404040”,
宽度:Ti.Platform.displayCaps.platformWidth,
高度:'100%',
zIndex:0
});
var checkEvaluation=Ti.UI.createImageView({
图像:imagesPath+“CheckEvaluation.png”,
不透明度:0,
左:20+dpi
});
var notYetEvaluation=Ti.UI.createImageView({
图片:imagesPath+“NotYetEvaluation.png”,
不透明度:0,
右图:20+dpi
});
backgroundWorkspace.add(检查评估);
backgroundWorkspace.add(notYetEvaluation);
var foregroundWorkspace=Ti.UI.createView({
顶部:0+dpi,
左:0+dpi,
背景颜色:“FFFFFF”,
宽度:Ti.Platform.displayCaps.platformWidth,
高度:'100%',
zIndex:1
});
var foregroughworkspacedraggable=Ti.UI.createView({
顶部:0+dpi,
左:0+dpi,
背景色:“透明”,
宽度:Ti.Platform.displayCaps.platformWidth,
高度:'100%',
zIndex:2
});
var-curX,curY;
var deltaX,deltaY;
var currentPositionX,currentPositionY;
var initialViewX=parseInt(foregroughworkspace.getLeft()),initialViewY=parseInt(foregroughworkspace.getTop());
var limitToTheRight=Ti.Platform.displayCaps.platformWidth/2.5;
var limitToTheLeft=(-1)*Ti.Platform.displayCaps.platformWidth/2.5;
var neutralColor=“#404040”;
var positiveColor=“#79b715”;
var negativeColor=“#9e9e9e”;
//touchstart事件
ForeGroundWorkSpaceDragable.addEventListener('touchstart',函数(e){
curX=e.x;
curY=e.y;
});
var hoveringOver=0;
//事件,这将处理拖动
ForeGroundWorkSpaceDragable.addEventListener('touchmove',函数(e){
var currentOpacity=当前位置X/限制到右侧;
如果(当前不透明度<0)
电流不透明度=0;
否则如果(当前不透明度>1)
电流不透明度=1;
检查评估。设置不透明度(currentOpacity);
var CurrentOpacityNotJet=当前位置X/限制至左侧;
if(currentOpacityNotYet<0)
currentOpacityNotYet=0;
else if(currentOpacityNotYet>1)
currentOpacityNotYet=1;
设置不透明度(currentOpacityNotYet);
deltaX=e.x-curX;
currentPositionX=initialViewX+deltaX;
如果(当前位置X>限制到右侧){
如果(悬停在上面!=1){
悬停=1;
backgroundWorkspace.animate({
背景颜色:正色,
持续时间:250
});
}
}否则如果(当前位置X限制到右侧){
foregroundWorkspace.animate({
左:Ti.Platform.displayCaps.platformWidth+dpi,
持续时间:500
},函数(){
自我激励({
高度:0+dpi,
持续时间:500
});
}); 

}否则,如果(currentPositionX我解决这个问题的方法是这样的:

在touchmove事件中,我只是将scrollview的scrollingEnabled属性的值更改为false,因此当我拖动其中一个元素时,滚动将被禁用。在touchend事件中,我再次启用了滚动。我传递了scrollview的setScrollingEnabled函数的引用

foregroundWorkspaceDraggable.addEventListener('touchmove', function(e) {

    setScrollingEnabled(false); //Added this

    var currentOpacity = currentPositionX / limitToTheRight;
    if(currentOpacity < 0)
        currentOpacity = 0;
    else if(currentOpacity > 1)
        currentOpacity = 1;
    checkEvaluation.setOpacity(currentOpacity);

    var currentOpacityNotYet = currentPositionX / limitToTheLeft;
    if(currentOpacityNotYet < 0)
        currentOpacityNotYet = 0;
    else if(currentOpacityNotYet > 1)
        currentOpacityNotYet = 1;
    notYetEvaluation.setOpacity(currentOpacityNotYet);

    deltaX = e.x - curX;
    currentPositionX = initialViewX + deltaX;

    if (currentPositionX > limitToTheRight) {
        if (hoveringOver != 1) {
            hoveringOver = 1;
            backgroundWorkspace.animate({
                backgroundColor : positiveColor,
                duration : 250
            });
        }
    } else if (currentPositionX <= limitToTheLeft) {
        if (hoveringOver != -1) {
            hoveringOver = -1;
            backgroundWorkspace.animate({
                backgroundColor : negativeColor,
                duration : 250
            });
        }
    } else {
        if (hoveringOver != 0) {
            hoveringOver = 0;
            backgroundWorkspace.animate({
                backgroundColor : neutralColor,
                duration : 250
            });
        }
    }
    foregroundWorkspace.setLeft(currentPositionX);
});

// event for touchend, this handles where the view remains in the end
foregroundWorkspaceDraggable.addEventListener("touchend", function(e){

    setScrollingEnabled(true); //Added this

    if (currentPositionX > limitToTheRight) {
        foregroundWorkspace.animate({
            left : Ti.Platform.displayCaps.platformWidth + dpi,
            duration : 500
        }, function() {
            self.animate({
                height : 0 + dpi,
                duration : 500
            });
        }); 
    } else if (currentPositionX <= limitToTheLeft) {
        foregroundWorkspace.animate({
            left : -Ti.Platform.displayCaps.platformWidth + dpi,
            duration : 500
        });
    } else {
        // alert('3');

        recallControl();
    }


});
ForeGroundWorkSpaceDragable.addEventListener('touchmove',函数(e){
setScrolingEnabled(false);//添加了此
var currentOpacity=当前位置X/限制到右侧;
如果(当前不透明度<0)
电流不透明度=0;
否则如果(当前不透明度>1)
电流不透明度=1;
检查评估。设置不透明度(currentOpacity);
var CurrentOpacityNotJet=当前位置X/限制至左侧;
if(currentOpacityNotYet<0)
currentOpacityNotYet=0;
else if(currentOpacityNotYet>1)
currentOpacityNotYet=1;
设置不透明度(currentOpacityNotYet);
deltaX=e.x-curX;
currentPositionX=initialViewX+deltaX;
如果(当前位置X>限制到右侧){
如果(悬停在上面!=1){
悬停=1;
backgroundWorkspace.animate({
背景颜色:正色,
持续时间:250
});
}
}否则如果(当前位置X限制到右侧){
foregroundWorkspace.animate({
左:Ti.Platform.displayCaps.platformWidth+dpi,
持续时间:500
},函数(){
自我激励({
高度:0+dpi,
持续时间: