gpt4 book ai didi

react-native - React Native Samsung One UI 3.0 Dimensions 屏幕宽度未返回正确值

转载 作者:行者123 更新时间:2023-12-03 16:47:07 24 4
gpt4 key购买 nike

我正在使用 react native 0.63.4,我使用 <View style={{flex: 1}}>对于每个页面的根元素。
我用 Dimensions.get("screen").width使元素具有响应性。由于某种原因,屏幕宽度的值不正确,而是一个更大的值。因此,屏幕上的每个元素都会变大。
预期行为:
Expected image .
问题:issue image
我已经用许多设备进行了测试。我只在 Galaxy S20 Ultra 和 S10 Lite 上看到这个问题。安装 Android 11 和 OneUi 3.0 更新后出现此问题。
代码:

const {height: screen_height, width: screen_width} = Dimensions.get('screen');

<View style={{ flex: 1,justifyContent:"center",alignItems:"center" }}>
<Text style={{fontSize:screen_width/15}}>text</Text>
</View>;
什么可能导致问题?
更新:仅当设备的屏幕分辨率设置为 3200x1440 时才会出现此问题。该应用程序在较低分辨率下按预期工作。

最佳答案

替换此代码:

const {height: screen_height, width: screen_width} = Dimensions.get('screen');
有了这个:
let scale = Dimensions.get('screen').scale / Dimensions.get('window').scale;
const screen_height = Dimensions.get('window').height * scale;
const screen_width = Dimensions.get('window').width * scale;

关于react-native - React Native Samsung One UI 3.0 Dimensions 屏幕宽度未返回正确值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65485878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com