React Native FlatList with columns, Last item width

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

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



        
相关标签:
8条回答
  • 2020-12-13 00:10

    You can try to get the current width of the device via Dimensions, do some math based on the number of columns you want to render, minus off the margins and set that as the minWidth and maxWidth.

    For example:

    const {height, width} = Dimensions.get('window');
    const itemWidth = (width - 15) / 2;
    
    <View style={{ flex: 1, margin: 5, backgroundColor: '#ffffd', minWidth: {this.itemWidth}, maxWidth: {this.itemWidth}, height: 130}} ></View>
    
    0 讨论(0)
  • 2020-12-13 00:12

    for your case use flex: 1/2

    therefore: Your item should have flex of 1/(number of columns) if you have 3 columns your item should have flex:1/3

    0 讨论(0)
提交回复
热议问题