答えて

2

私は、静的なグリッドビューを達成するためにScrollViewとフレキシボックスの組み合わせを使用しています。

import {Dimensions} from 'react-native'; 

.... 

return (
    <ScrollView> 
    <View style={styles.container}> 
     { 
     this.props.categories.map((category, index) => { 
      return (
      <TouchableOpacity 
       key={index} 
       style={styles.item} 
       onPress={() => {}} 
      > 
       <Image 
       style={styles.itemIcon} 
       source="..." 
       /> 
       <Text style={styles.itemTitle}> 
       {category.name} 
       </Text> 
      </TouchableOpacity> 
     ) 
     }) 
     } 
    </View> 
    </ScrollView> 
) 

var styles = StyleSheet.create({ 
    container: { 
     flexDirection: 'row', 
     flexWrap: 'wrap' 
    }, 
    item: { 
     width: Dimensions.get('window').width * 0.5, 
     height: 100, 
     borderWidth: 1, 
     borderColor: "lightgray", 
     alignItems: 'center', 
     justifyContent: 'center'   
    }, 
    itemIcon: { 
     width: 100, 
     height: 100, 
     resizeMode: 'contain' 
    }, 
    itemTitle: { 
     marginTop: 16, 
    }, 
}); 
+0

3列を扱うには? 'Dimensions.get( 'window')。width * 0.3333 ...'? – junlin

+0

はい、幅を '' 'Dimensions.get( 'window')に設定することができます。width * 0.33''' – Kelvin

関連する問題