1

我想在 react-native 中使用 ImageBackground 在特定位置显示文本。

使用调整大小模式作为包含时,如何为不同的屏幕尺寸指定不同的绝对位置?

https://i.stack.imgur.com/HRUwn.png

 <ImageBackground
      source={require("../../assets/image.png")}
      style={{ width: "100%", height: "100%", position: "relative" }}
      resizeMode="contain"
      onLayout={(event) => this.setLayout(event.nativeEvent.layout)}
    >
      <Text
        style={{
          position: "absolute",
          left: 90,
          top: 300,
        }}
      >
        Text_1
      </Text>
      <Text
        style={{
          position: "absolute",
          left: 280,
          top: 300,
        }}
      >
        Text_2
      </Text>
    </ImageBackground>
4

1 回答 1

0

使用尺寸给出左右位置。示例如下,

import { Dimensions } from 'react-native';

const window = Dimensions.get('window');

<View style={{
      flexdirection:'row', 
      justifyContent:'space-between',
      marginLeft:(window.width)*0.3,
      marginRight:(window.width)*0.5,
      top:(window.height)*0.25,
      position: "absolute",
}}>
 <Text>Text One </Text>
 <Text>Text Two </Text>
</View>
    
    
于 2020-12-25T15:12:57.457 回答