show 2 items per row[react native]

后端 未结 5 1206
借酒劲吻你
借酒劲吻你 2020-12-15 17:40

I am learning react native and in all the tutorials i see ListView has been used with only 1 items per row. I have not used ListView, though. I have only 6 items that has to

5条回答
  •  醉梦人生
    2020-12-15 18:38

    To make a 2 row grid using ListView you could use this code as an example:

    renderGridItem( item ){
        return (
            
                
                    {item.fields.name.charAt(0).toUpperCase()}
                
            
            {item.fields.name} 
        
        );
    }
    
    renderCategories(){
    
        var listItems = this.dsinit.cloneWithRows(this.state.dataSource);
    
        return (
            
                 this.renderGridItem(item)}
                />
            
        );
    }
    
    const styles = StyleSheet.create({
        grid: {
            justifyContent: 'center',
            flexDirection: 'row',
            flexWrap: 'wrap',
            flex: 1,
        },
        gridItem: {
            margin:5,
            width: 150,
            height: 150,
            justifyContent: 'center',
            alignItems: 'center',
        },
        gridItemImage: {
            width: 100,
            height: 100,
            borderWidth: 1.5, 
            borderColor: 'white',
            borderRadius: 50,
        },
        gridItemText: {
            marginTop: 5,
            textAlign:'center',
        },
    });
    

    Change styles to choose how many rows you want to see on screen. This code is responsive.

提交回复
热议问题