我正在将React项目转换为React Native,需要帮助在React Native中设置网格布局.我想设置一个5列x行(行数可能不同)视图.我已经使用了react native tableview simple包,但我无法指定单元格的跨度.我还try 了react-native flexbox网格包,我可以设置列,但我仍然无法设置特定单元格的跨度宽度.我想知道有什么我可以用的.

作为参考,我希望我的桌子看起来像这样:

     |Col 1|Col 2|Col 3|Col 4|Col 5|
     |------------------------------
Row 1|     Text        | Yes |  No | 
     |------------------------------
Row 2|     Text        | Yes |  No | 
     |------------------------------
Row 3|     Text        |  Dropdown | 

推荐答案

你可以不用任何软件包就可以做到这一点.如果每一行都完全相同,那么执行以下操作应该可以解决您的问题;

export default class Table extends Component {
    renderRow() {
        return (
            <View style={{ flex: 1, alignSelf: 'stretch', flexDirection: 'row' }}>
                <View style={{ flex: 1, alignSelf: 'stretch' }} /> { /* Edit these as they are your cells. You may even take parameters to display different data / react elements etc. */}
                <View style={{ flex: 1, alignSelf: 'stretch' }} />
                <View style={{ flex: 1, alignSelf: 'stretch' }} />
                <View style={{ flex: 1, alignSelf: 'stretch' }} />
                <View style={{ flex: 1, alignSelf: 'stretch' }} />
            </View>
        );
    }

    render() {
        const data = [1, 2, 3, 4, 5];
        return (
            <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
            {
                data.map((datum) => { // This will render a row for each data element.
                    return this.renderRow();
                })
            }
            </View>
        );
    }
}

React-native相关问答推荐

如何重复使用expo 音频对象S录音?

获取 TypeError:this.InnerNativeModule.configureProps 不是 mac 上 expo 中的函数

reactnavigation后退按钮的自定义后退导航

使用 resizeMode 封面截断的图像

无法访问函数内部的状态

使用 Android NDK 在 C 或 C++ 中创建 react-native Native Module?

使用直接在 Windows 中运行的模拟器在 WSL 中运行 React Native

在 Windows 上进行本机调试

React Native - NSNumber 无法转换为 NSString

react native图像不适用于特定 URL

如何使用功能组件向 ref 公开功能?

xcode 8.3 框架未找到架构 armv7 的 FileProvider

React Native 检测点击 View

将 React Native 升级到 0.60-RC2 后找不到库libjsc.so

在 React Native Navigator 中的组件之间传递值

动态改变 React Native Flat List 中的列数

ReactNative TextInput 不可见 iOS

如何在 React Native 中更改 textInput 占位符的字体系列

React 在任何根目录中都找不到入口文件

zIndex 不适用于react-native元素