我正在学习React Native,并试图将徽标和登录表单一个在另一个下面。
下面是我的代码:
import { StatusBar } from "expo-status-bar";
import { View } from "react-native";
import { HomeStyles as styles } from "../styles/home.css";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { TextInput, Button } from "@react-native-material/core";
import { Image } from "expo-image";
import { Stack, HStack, VStack } from "react-native-flex-layout";
export default function Home() {
return (
<SafeAreaProvider>
<View style={styles.container}>
<View style={styles.imageWrapper}>
<Image
style={styles.image}
source="https://st2.depositphotos.com/4035913/6124/i/450/depositphotos_61243733-stock-illustration-business-company-logo.jpg"
contentFit="scale-down"
/>
</View>
<View style={styles.form}>
<TextInput
style={styles.username}
label="Username"
variant="outlined"
/>
<TextInput
style={styles.password}
secureTextEntry={true}
label="Password"
variant="outlined"
/>
<Button style={styles.btnSubmit} title="Submit" />
</View>
</View>
</SafeAreaProvider>
);
}
和样式
import { StyleSheet, Text, View } from "react-native";
export const HomeStyles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
padding:10
},
imageWrapper:{
flex: 1,
width:'75%',
alignItems: "center",
justifyContent: "center",
borderWidth:1,
borderColor:'#000'
},
image: {
flex:1,
width:'100%',
height: 100,
alignItems: "center",
justifyContent: "center",
},
form: {
flex:1,
flexGrow:1,
width:'100%',
alignItems: "center",
justifyContent: "center",
},
username: {
alignItems: "center",
justifyContent: "center",
marginBottom:15,
borderColor: '#0a4b7c',
outlineColor: '#0a4b7c',
},
password: {
alignItems: "center",
justifyContent: "center",
marginBottom:15,
},
btnSubmit: {
width:'100%',
backgroundColor:'#0a4b7c',
height: 60,
alignItems: "center",
justifyContent: "center",
},
});
如果你看到输出,图像占据了50%的高度。如何对齐图像只占30%,其次是表格。
你可以看到白色空间。图像周围的边框用于视觉识别。
2条答案
按热度按时间njthzxwz1#
imageWrapper
和form
都将flex
设置为1,这意味着两个视图都将获得1/2的空间。将imageWrapper的height
设置为30%。大概是这样的:eanckbw92#
应该对把戏