【问题标题】:Consuming space in react native在本机反应中消耗空间
【发布时间】:2020-09-08 14:57:10
【问题描述】:

如何包装图像和文本以仅使用正确的高度?

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

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'
    }

})

【问题讨论】:

  • 如果您可以向我们提供您的问题的工作 html 示例,我们会更容易为您提供帮助

标签: javascript css react-native flexbox


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 2019-09-14
    • 1970-01-01
    • 2017-02-25
    • 2019-06-03
    • 2017-10-07
    • 1970-01-01
    相关资源
    最近更新 更多