提问者:小点点

在react native中消耗空间


我如何包装图像和文字,以只使用正确的高度量?

这是我现在实现的图像,但这不是我想要的,因为我有一个表单下面不会显示,因为文本标题和图像占用了很多空间。

Home file
<Container>
  <ImageBackground style={styles.container} source={require('../../../assets/BG_SignIn.png')}>
   <Header />
   <Form />
  </ImageBackground>
</Container>

头文件

<View style={styles.header}>
    <View style={styles.signInHeader}>
       <H1>Sign In</H1>
        <Text>I don't have an account, yet.</Text>
    </View>
    <View style={styles.birdHeader}>
       <Birds width="100%" height="100%" />
    </View>

<Form>
            <Item floatingLabel>
                <Label>Mobile / Email</Label>
                <Input />
            </Item>
            <Item floatingLabel>
                <Label>Password</Label>
                <Input secureTextEntry={true} />
            </Item>
            <Button block rounded style={{ marginTop: 20, backgroundColor: "white" }}>
                <Text style={{ color: "#018377", fontSize: 20 }}>Sign In</Text>
            </Button>
            <Text style={{ margin: 15, }}>Forgot your password?</Text>
        </Form>
</View>

const styles = StyleSheet.create({
    header: {
        display: "flex",
        flexDirection: "row",
        flex: 1
    },
    signInHeader: {
        flex: 4,
        marginTop: 20,
        borderWidth: 1,
        borderColor: 'red',
    },
    birdHeader: {
        flex: 2,
        borderWidth: 1,
        borderColor: 'red'
    }

})

共1个答案

匿名用户

只需在视图中包装并按您的需要设置flex即可

<View style={{flex: 0.5}}>
    <View style={styles.signInHeader}>
        <H1>Sign In</H1>
        <Text>I don't have an account, yet.</Text>
    </View>
    <View style={styles.birdHeader}>
        <Birds width="100%" height="100%" />
    </View>
</View>

<View style={{flex: 0.5}}>
    <Form>
        ...
    </Form>
</View>