【问题标题】:Can you help me with layouts on react native app? [closed]你能帮我处理本机应用程序的布局吗? [关闭]
【发布时间】:2026-02-02 23:15:01
【问题描述】:

如何在 react native 上创建 this 布局?你能给我举个例子吗?我不明白如何创建它,因为这里的 css 很差。

【问题讨论】:

    标签: javascript reactjs flexbox react-native


    【解决方案1】:

    Here你去。这应该让您对如何在 React Native 中使用样式有一个很好的了解。示例代码如下:

    https://rnplay.org/apps/W0vWoQ

    其中一个主要概念是 Flexbox 用于布局,所以我会看一下。 Here 是样式的总体概述。

    var SampleApp = React.createClass({
      render: function() {
        return (
          <View style={styles.container}>
            <View style={styles.one}><Text style={styles.logo}>Text Logo</Text></View>
            <View style={styles.two}></View>
            <View style={styles.three}>
                <Text>Some Texxt</Text>
              </View>
          </View>
        );
      }
    });
    
    var styles = StyleSheet.create({
      container: {
        flex: 1,    
      },
      logo: {
        color: 'white'
      },  
        one: {
            flex:2,
        backgroundColor: 'black'
        },
     two: {
            flex:7,
            backgroundColor: 'white'
      },
        three: {
        flex: 1,
        backgroundColor: 'white',
        borderTopWidth:4,
    
        }
    });
    

    【讨论】:

    • 非常感谢!还有一个问题:如何创建 100% 宽度的按钮?
    • 确实有很多不同的方法可以做到这一点,其中许多取决于它们所在容器的状态。无论如何,我已经编辑了上面的示例并添加了一个全宽按钮这适用于上述设置方式。