reactjs - 弯曲方向 : 'row' is not working in FlatList

标签 reactjs react-native

我试图获得低于输出的结果,但 flexDirection: 'row' 无法正常工作。请任何人都可以解释一下如何获得以下输出。如有任何帮助,我们将不胜感激。

**所需输出:** enter image description here

我的输出: enter image description here

我的代码是:

_renderItem(rowData) {
    return(
       <View style={{flex: 1, flexDirection: 'row', flexWrap: 'wrap'}}>
           <View style={{margin: 2, width: '24%', backgroundColor: '#fff', borderWidth: 1, borderColor: '#aaa'}}>
                <TouchableOpacity activeOpacity={0.9} style={{height: 190}}>
                    <Image source={{uri: rowData.item.images[0].src}} style={{height: '100%', width: '100%'}}/>
                </TouchableOpacity>
                <View style={{padding: 5}}>
                    <TouchableOpacity activeOpacity={0.9} style={{flexDirection: 'row', justifyContent: 'space-between'}}>
                        <View>
                            <CapitalizedText style={{color: '#666', fontSize: 14}}>{rowData.item.title}</CapitalizedText>
                            <Text style={{fontSize: 15, color: '#666', justifyContent: 'center', alignItems: 'center'}}>{'₹' + rowData.item.variants[0].price}</Text>
                        </View>
                        <Icon size={24} color="#aaa" name="turned-in-not" />
                    </TouchableOpacity>
                    <CapitalizedText style={{fontSize: 14, color: '#bbb'}}>Printed Top</CapitalizedText>
                </View>
            </View>
         </View>
    );
}
render() {
   return(
       <View>
          {
             this.state.product_detail.length <= 0 ?
                <ActivityIndicator color = '#bc2b78' size = "large" style={{alignItems: 'center', justifyContent: 'center'}} />
          :
                <FlatList
                    keyExtractor = {( item, index ) => index }
                    data = { this.state.product_detail }
                    renderItem = {(rowData) => this._renderItem(rowData)}
                    ListFooterComponent = { this._render_Footer }
                />
          }
        </View>
);}

谢谢。

最佳答案

使用 flatList 中的 numColumns 属性将 flatList 的文本项对齐在一行中,例如

let numColumns=5;
<FlatList numColumns={numColumns}/>

关于reactjs - 弯曲方向 : 'row' is not working in FlatList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50187009/

相关文章:

android - 如何在 React Native 中从@ReactMethod 返回一个 bool 值?

android - 在 android P 上 react Native

reactjs - 在 dropzone-material-ui 中更改段落样式

node.js - 清除选定的值和列表

reactjs - JestJS -> 不变违规 : Could not find "store" in either the context or props of "Connect(Portfolio)"

javascript - React Native 中的偏移 RefreshControl

javascript - 在没有 React.memo 的情况下使用 useCallback 有什么好处吗?

javascript - 如何使时区偏移以 24 小时格式正确显示

android - React-native Android Systrace HTML 在 Ubuntu 14.04 中是空白的

javascript - KeyboardAvoidingView - 隐藏键盘时重置高度