【发布时间】:2023-01-28 01:12:34
【问题描述】:
我是 React Native 的新手,我正在尝试构建一个应用程序,因此出于测试目的,我在 Android Emulator 中使用 Pixel 4,所以我根据 Pixel 4 分辨率设计了我的应用程序,但是当我在 Nexus 5 等其他设备中检查我的应用程序时一半的内容无法正确显示在屏幕上。那么,我该如何设计为不同设备自动设置分辨率的代码呢?
我也附上问题图片:
On Pixel 4 (this one is perfect) On Nexus 5
这是我试过的
`import { View, Text, Image, StyleSheet, StatusBar } from "react-native";
import React from "react";
import { SafeAreaView } from "react-native-safe-area-context";
import { Button } from "react-native-paper";
import { useNavigation } from "@react-navigation/native";
`const SplashScreen = () => {
const navigation = useNavigation();
return (
<SafeAreaView
style={{
height: "auto",
}}
>
<StatusBar
translucent={true}
backgroundColor={"transparent"}
barStyle="dark-content"
/>
<View style={styles.container}>
<View className="w-[90%] flex items-center justify-center">
<Text
className="text-slate-500 text-2xl z-10"
style={{ fontFamily: "regular" }}
>
Taste of
</Text>
<Text
className="text-slate-500 text-2xl mt-3 z-10"
style={{ fontFamily: "regular" }}
>
Every Household
</Text>
</View>
<View>
<Image
source={require("../assets/logo.png")}
className="h-[380px] w-[380px] object-cover mt-5 ml-2"
/>
<View className="flex items-center justify-center -mt-5">
<Text
style={{
fontFamily: "rog",
fontSize: 23,
color: "#1D2044",
marginBottom: 10,
zIndex: 10,
}}
>
by
</Text>
<Text
style={{
fontFamily: "rog",
fontSize: 33,
color: "#1D2044",
zIndex: 10,
}}
>
imexture
</Text>
</View>
</View>
<View className="w-[90%] mt-24 z-10">
<Button
style={styles.radioButton}
onPress={() => navigation.navigate("Login")}
>
<Text
className="text-white text-xl tracking-widest"
style={{ fontFamily: "regular" }}
>
Let's Go
</Text>
</Button>
</View>
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
justifyContent: "center",
alignItems: "center",
height: "100%",
},
radioButton: {
backgroundColor: "#1D2044",
borderRadius: 10,
borderColor: "#1D2044",
padding: 8,
},
});
export default SplashScreen;`
`我也试过 React-Native Dimensions 但问题仍然存在
【问题讨论】:
标签: react-native screen-resolution