flex:1不能填满整个屏幕

时间:2018-06-26 17:05:24

标签: javascript css css3 react-native flexbox

我正在尝试更改应用程序的背景颜色,但该颜色无法填充整个屏幕。当我将flex设置为0时,背景色仅覆盖所需的数量,但是当我将其设置为1时,它不会缩小整个屏幕,而是会缩小。我做错了什么?

with flex 0

with flex 1

下面是代码,更改了根视图的flex:       render(){     返回(                                    

    <Text>{welcome}</Text>

    <TextInput
      underlineColorAndroid="rgba(0,0,0,0)"
      placeholder={email}
      autoCapitalize="none"
      style={styles.textInput}
      onChangeText={email1 => this.setState({ email1 })}
    />
    <TextInput
      underlineColorAndroid="rgba(0,0,0,0)"
      secureTextEntry
      placeholder={password}
      autoCapitalize="none"
      style={styles.textInput}
      onChangeText={password1 => this.setState({ password1 })}
      value={this.state.password1}
    />
    {this.state.errorMessage && (
      <Text style={styles.error}>{this.state.errorMessage}</Text>
    )}
    <TouchableOpacity
      onPress={this.handleSignUp}
      style={styles.buttonContainer}
    >
      <Text style={styles.buttonText}>{signup}</Text>
    </TouchableOpacity>

    <Text
      style={styles.text}
      onPress={() => this.props.navigation.navigate("LoginScreen")}
    >
      {already_have_an_account}
    </Text>
  </KeyboardAvoidingView>
);

} }

    const styles = StyleSheet.create({
    container: {
      justifyContent: "center",
      padding: 20,
      backgroundColor: "red",
      flex: 0
    },
    textInput: {
      height: 40,
      marginTop: 8,
     paddingHorizontal: 8,
      backgroundColor: "#e2e2e2"
    },
    buttonContainer: {
      backgroundColor: "#3bd774",
      padding: 15,
      marginTop: 10
    },

  buttonText: {
    textAlign: "center",
    color: "white",
    fontWeight: "bold"
  },

  logo: {
    width: 200,
    height: 200
  },

  logoContainer: {
    alignItems: "center",
    justifyContent: "center"
  },

  text: {
    marginTop: 16,
    color: "#bcbcbc",
    textAlign: "center"
  },

  error: {
    marginTop: 8,
    color: "red"
  }
});

2 个答案:

答案 0 :(得分:0)

将整个布局放入View包装器中,并为此视图赋予这种样式

onOrg3Change

运行示例:https://snack.expo.io/Hy-Gv-lGm

答案 1 :(得分:0)

您需要确保在视图链中一直具有flex:1。这是因为flex:1将使视图填充其父视图

我可以看到您复制/粘贴的内容不是全部代码,因为有import tensorflow as tf with tf.variable_scope("model"): y = 1 with tf.variable_scope("model2"): z = 1 但没有开始标签。

因此,至少您需要一个</KeyboardAvoidingView>,但是如果有包装的内容,则还应在该控件中添加flex:1。