Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React-Native:React-Native能否找到每个设备的确切绝对位置?_Reactjs_React Native_Imagebackground - Fatal编程技术网

Reactjs React-Native:React-Native能否找到每个设备的确切绝对位置?

Reactjs React-Native:React-Native能否找到每个设备的确切绝对位置?,reactjs,react-native,imagebackground,Reactjs,React Native,Imagebackground,我想用绝对位置在图像上显示文本。 但是,由于每个设备的屏幕大小不同,因此很难确定准确的位置 有没有办法计算出准确的位置 我发布了一个类似的问题,但我没有得到我想要的答案。 下面是我尝试过的代码 <ImageBackground source={require("../../assets/brain/ohi.png")} style={{ width: "100%", height: "100%", p

我想用绝对位置在图像上显示文本。 但是,由于每个设备的屏幕大小不同,因此很难确定准确的位置

有没有办法计算出准确的位置

我发布了一个类似的问题,但我没有得到我想要的答案。

下面是我尝试过的代码

 <ImageBackground
      source={require("../../assets/brain/ohi.png")}
      style={{ width: "100%", height: "100%", position: "relative" }}
      resizeMode="contain"
      onLayout={(event) => this.setLayout(event.nativeEvent.layout)}
    >
      <Text
        style={{
          position: "absolute",
          left: windowWidth * 0.22,
          top: windowHeight * 0.4,
        }}
      >
        Text_1
      </Text>
      <Text
        style={{
          position: "absolute",
          left: 280,
          top: 300,
        }}
      >
        Text_2
      </Text>
    </ImageBackground>
this.setLayout(event.nativeEvent.layout)}
>
正文1
文本2
请参阅

请注意,
layout
对象的
x
y
坐标相对于使用
onLayout
的组件的直接父组件。在您的例子中,
ImageBackground
的布局是相对于立即包装它的内容进行的

文本
像这样放置的一个可能解决方案是组合树,如

const[layout,setLayout]=useState();
setLayout(event.nativeEvent.layout)}/>