Répondre

1

Pour le défilement horizontal:

<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> 

Pour le défilement vertical:

<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> 

titane classique Exemple

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

Votre point clé pour restreindre la direction de défilement sur Android est la propriété scrollType.

+0

Je n'utilise pas d'alliage. Comment puis-je résoudre ce problème à partir du fichier javascript? Je n'ai pas utilisé d'alliage. –

+0

Il suffit de définir la propriété scrollType sur "horizontal" ou "vertical" en fonction de votre cas, comme dit Prashant Saini –

+0

Edited my answer with Classic code. Mais il est recommandé de mieux s'habituer à Alloy dès que possible avant de commencer à faire face à d'énormes codes et donc à un grand nombre de problèmes comme des erreurs de syntaxe ou d'autres erreurs de codage. –