1

I want to create a two row list. This is the result I want to achieve

enter image description here

I tried to use flatList with this code

    <FlatList
    style={styles.list}             //<-- This Line
    numColumns={2}                                  //<-- And this one
    data={[{key: 'row1'}, {key: 'row2'},{key: 'row3'},{key: 'row4'}]}
    renderItem={({item}) => 
    <View>
    <Text>{item.key}</Text>
    </View>
  } />

But I got his result

enter image description here

I also tried to put the width of each item to the half of the screen width with this code

<View style={{width: width /2}}>
<Text>{item.key}</Text>
</View>

But it dose not work when the device orientation changes.

What I want to achieve is to create a virtual table that have the width of the screen and put the text in the beginning of each cell. Something like this

+------------------------------+-----------------------------+
| item 1.                      | item 2.                     |
+------------------------------+-----------------------------+
| item 3.                      | item 4                      |
+------------------------------+-----------------------------+
| item5                        | item 6                      |
+------------------------------+-----------------------------+

Do you know how to achieve that?

user567
  • 3,712
  • 9
  • 47
  • 80

1 Answers1

0

You simply have to add flex:1 to your parent view inside of your renderItem prop. Like so

<FlatList
   style={{flex: 1}} //whatever style you had          
   numColumns={2}                                  
   data={[{key: 'row1'}, {key: 'row2'},{key: 'row3'},{key: 'row4'}]}
   renderItem={({item}) =>
       <View style = {{flex: 1}}>
           <Text>{item.key}</Text>
       </View>
   } 
/>
Ryan Turnbull
  • 3,766
  • 1
  • 25
  • 35