React Native 位置:“绝对”不起作用

问题描述 投票:0回答:1

我是react-native的新手,我是从youtube学习的,但是其中用于在屏幕顶部对齐徽标图像的代码块有效,但是对我来说该代码不起作用。视频的确切时间戳是这里

以下是我的代码:

import React from "react";
import { ImageBackground, StyleSheet, View, Image, Text } from "react-native";

function WelcomeScreen(){
    return (
        <ImageBackground style={styles.background} >
            <View styles={styles.logoContainer}>
                <Image styles={styles.logo} source={require('../assets/favicon.png')} />
                <Text>Don't know why isn't it working</Text>
            </View>
            <View style={styles.loginButton}></View> 
            <View style={styles.registerButton}></View>    
        </ImageBackground>
    );
}

const styles = StyleSheet.create({
    background: {
        flex: 1,
        justifyContent: "flex-end",
        alignItems: "center",
        borderColor: "#FF0000",
        borderWidth: 2
    },
    loginButton: {
        width: "100%",
        height: 60,
        backgroundColor: "#FD7E14",
        borderColor: "#FF0000",
        borderWidth: 2
    },
    logo: {
        width: 200,
        height: 200,
    },
    logoContainer: {
        position:"absolute",
        top: 70,
        alignItems: "center",
        borderColor: "#FF0000",
        borderWidth: 2
    },
    registerButton: {
        width: "100%",
        height: 60,
        backgroundColor: "#2196F3",
        borderColor: "#FF0000",
        borderWidth: 2
    },
})

export default WelcomeScreen;

在这里,我试图将

logoContainer
view
放在屏幕的上半部分,但我无法获得所需的结果,请帮助我对齐。
App.js

import WelcomeScreen from "./app/screens/WelcomeScreen"

export default function App() {

  return (
    <WelcomeScreen />
  );
}

如果可能的话,请分享学习视图定位的参考资料,因为它已经成为我最大的障碍。

react-native flexbox expo
1个回答
0
投票

也许您需要将

styles
更改为
style

© www.soinside.com 2019 - 2024. All rights reserved.