React Native FlatList with columns, Last item width

后端 未结 8 1028
北恋
北恋 2020-12-12 23:40

I\'m using a FlatList to show a list of items in two columns



        
8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 00:08

    @Emilius Mfuruki suggestion is good, but if you have text with varying length it doesn't work perfectly. Then use this width inside your item view:

    const {height, width} = Dimensions.get('window');
    const itemWidth = (width - (MarginFromTheSide * 2 + MarginInBetween * (n-1))) / n;
    

    In FlatList use:

    columnWrapperStyle={{
                flex: 1,
                justifyContent: 'space-evenly',
              }}
    

    Works perfectly.

提交回复
热议问题