【问题标题】:Titanium Android Horizontal & Vertical ScrollTitanium Android 水平和垂直滚动
【发布时间】:2016-12-29 10:25:59
【问题描述】:

Titanium appcelerator 水平滚动时,ui 垂直滚动。无论如何在水平滚动时锁定垂直滚动?

【问题讨论】:

    标签: titanium appcelerator horizontal-scrolling vertical-scrolling


    【解决方案1】:

    水平滚动:

    <Alloy>
        <Window backgroundColor="white">
            <ScrollView backgroundColor="gray" layout="horizontal" width="Ti.UI.FILL" height="Ti.UI.SIZE" scrollType="horizontal">
                <View left="10" width="100" height="100" backgroundColor="red" />
                <View left="10" width="100" height="100" backgroundColor="red" />
                <View left="10" width="100" height="100" backgroundColor="red" />
                <View left="10" width="100" height="100" backgroundColor="red" />
                <View left="10" width="100" height="100" backgroundColor="red" />
                <View left="10" width="100" height="100" backgroundColor="red" />
                <View left="10" width="100" height="100" backgroundColor="red" />
                <View left="10" width="100" height="100" backgroundColor="red" />
                <View left="10" width="100" height="100" backgroundColor="red" />
            </ScrollView>
        </Window>
    </Alloy>
    

    垂直滚动:

    <Alloy>
        <Window backgroundColor="white">
            <ScrollView backgroundColor="gray" layout="vertical" width="Ti.UI.SIZE" height="Ti.UI.FILL" scrollType="vertical">
                <View top="10" width="100" height="100" backgroundColor="red" />
                <View top="10" width="100" height="100" backgroundColor="red" />
                <View top="10" width="100" height="100" backgroundColor="red" />
                <View top="10" width="100" height="100" backgroundColor="red" />
                <View top="10" width="100" height="100" backgroundColor="red" />
                <View top="10" width="100" height="100" backgroundColor="red" />
                <View top="10" width="100" height="100" backgroundColor="red" />
                <View top="10" width="100" height="100" backgroundColor="red" />
                <View top="10" width="100" height="100" backgroundColor="red" />
            </ScrollView>
        </Window>
    </Alloy>
    

    钛经典示例

    var win = Ti.UI.createWindow({
        backgroundColor : 'white'
    });
    
    var scrollview = Ti.UI.createScrollView({
        backgroundColor : "gray",
        layout : "horizontal",
        width : Ti.UI.FILL,
        height : Ti.UI.SIZE,
        scrollType : "horizontal"
    });
    
    for (var i=0; i<=10; i++) {
        scrollview.add(createView());
    }
    
    win.add(scrollview);
    
    win.open();
    
    function createView() {
        return Ti.UI.createView({
            backgroundColor : 'red',
            width : 100,
            height : 100,
            left : 10
        });
    }
    

    您在 Android 上限制滚动方向的关键点是 scrollType 属性。

    【讨论】:

    • 我没有使用合金。我怎样才能从 javascript 文件中解决这个问题?我没有使用合金。
    • 只需将 scrollType 属性设置为“水平”或“垂直”,具体取决于您的情况,就像 Prashant Saini 说的那样
    • 用经典代码编辑了我的答案。但建议您在开始面临大量代码并因此出现大量问题(如语法错误或其他编码错误)之前,最好尽快习惯 Alloy。
    猜你喜欢
    • 1970-01-01
    • 2016-10-26
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多