【发布时间】:2021-07-23 03:10:00
【问题描述】:
我有一个水平的 ScrollView 组件,它在 React Native 中包裹了整个屏幕,它的第一个子组件是一个占据整个设备高度的图像,并延伸到设备宽度之外。我试图在背景图像中绝对定位元素,以便它们在不同设备上始终处于与背景相同的相对位置,但我不知道如何。任何帮助将不胜感激。
当前代码示例:
<View style={styles.container}>
<ScrollView horizontal={true} bounces={false}>
<ImageBackground style={styles.backgroundImage}>
<Element style={{position: "absolute", top: "30%", left: "50%"}}>
</ImageBackground>
</ScrollView>
</View>
const styles = StyleSheet.create({
container: {
flex: 1,
height: SCREEN.height,
},
backgroundImage: {
height: SCREEN.height,
width: SCREEN.height * 1.125,
},
})
问题是具有绝对定位的元素最终会在不同设备上的背景图像的不同位置。有可能解决这个问题吗?
【问题讨论】:
标签: css react-native scrollview horizontalscrollview