ListView grid in React Native

后端 未结 9 1968
长发绾君心
长发绾君心 2020-11-28 02:18

I\'m building a simple app in React Native that fetches listings from a remote JSON source and displays them on screen.

So far, using the excellent example here, I\

9条回答
  •  醉梦人生
    2020-11-28 02:42

    Follow Colin Ramsay's answer. And if you want half width for each item, try this way.

    ...
    import { Dimensions } from 'react-native'; 
    const { width, height } = Dimensions.get('window');
    const gutter = 0; // You can add gutter if you want
    ...
    
    
    const styles = StyleSheet.create({
      item: {
        width: (width - gutter * 3)/2,
        marginBottom: gutter,
        flexDirection: 'column',
        alignSelf: 'flex-start',
        backgroundColor: '#ff0000',
      },
      list: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        flexWrap: 'wrap',
        paddingHorizontal: gutter,
      },
    });
    

提交回复
热议问题