回答

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属性。

+0

我不使用合金。我怎样才能解决这个从JavaScript文件?我没有使用合金。 –

+0

只需将scrollType属性设置为“水平”或“垂直”,具体取决于您的情况,例如Prashant Saini说 –

+0

使用经典代码编辑了我的答案。但是,建议您在开始面对巨大的代码之前尽快熟悉Alloy,因此会遇到大量问题,如语法错误或其他编码错误。 –