Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

javascript - Maping in scrollview makes horizontal list vertical in React Native

I have two queries actually. I am using ScrollView in my app. The list shows horizontal when i give static images in scrollview like this:

<View>
  <View style={{width:width,paddingHorizontal:20,paddingVertical:20}}>
  <ScrollView 
    horizontal={true}
    showsHorizontalScrollIndicator={false}
    scrollEventThrottle={200}
    decelerationRate="fast"
    pagingEnabled>
  <Image source={{uri:'https://reactjs.org/logo-og.png'}} 
        style={{width: 80, height: 80}} />
  <Image source={{uri:'https://reactjs.org/logo-og.png'}} 
        style={{width: 80, height: 80}} />
  <Image source={{uri:'https://reactjs.org/logo-og.png'}} 
        style={{width: 80, height: 80}} />
  <Image source={{uri:'https://reactjs.org/logo-og.png'}} 
        style={{width: 80, height: 80}} />
  </ScrollView>
 </View>
</View>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this way

return (
  <ScrollView
    horizontal={true}
    showsHorizontalScrollIndicator={false}
    scrollEventThrottle={200}
    decelerationRate="fast"
    pagingEnabled
  >
    <View>
      list.map(function(item, i)
      {
        <TouchableOpacity
          onPress={() => alert(item)}
          key={i}
          style={{ width: width, paddingHorizontal: 20, paddingVertical: 20 }}
        >
          <Image source={{ uri: item }} style={{ width: 80, height: 80 }} />
        </TouchableOpacity>
      }
      )
    </View>
  </ScrollView>
);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...