【问题标题】:How to add buttons grid style in React Native?如何在 React Native 中添加按钮网格样式?
【发布时间】:2016-07-26 23:44:42
【问题描述】:

我最近将手放在 react-native 上,并试图将按钮动态添加到视图中。我想要这样的结构:

(在引导程序中我会添加一个带有 col-md-4 的类)

[A] [A] [A] [A]

[A] [A] [A] [A] 

[A] [A] [A] [A] 

我已经可以添加按钮,但它们总是出现在新行中。

[A]
[A]
[A]

目前我添加的样式和功能:

const styles = StyleSheet.create({
    container: {
        marginTop: 65,
        flex: 1,
    },
})

render(){
    return (
        <View style={styles.container}>
            {this.renderButtons()}
        </View>
    )
}
renderButtons(){
    var list = myArray.map((item, index) => {
        return (
            <View key={index}>
                <TouchableHighlight
                    style={styles.button}>
                </TouchableHighlight>
            </View>
        )
    })
    return list;
}

我知道我应该在 renderButtons 下的 View 中添加某种样式,但我不知道从哪里开始。然而。

【问题讨论】:

    标签: css react-native flexbox


    【解决方案1】:

    正确的做法是在你的样式中使用flexWrap: "wrap"

    【讨论】:

      【解决方案2】:

      在 React Native 中,默认的 flexDirectioncolumn,这意味着弹性项目将垂直堆叠。

      您需要将flexDirection 切换为row

      参考资料:

      【讨论】:

        猜你喜欢
        • 2015-07-04
        • 1970-01-01
        • 2016-04-10
        • 2020-11-19
        • 1970-01-01
        • 1970-01-01
        • 2021-04-11
        • 1970-01-01
        相关资源
        最近更新 更多