我刚接触React-native,我有一个非常简单(至少我这么认为)的问题。
我有一个带有resizeMode='contain'的ImageBackground,现在我想把背景定位到容器的顶部……
<ImageBackground style={styles.imageBackground} source={backgroundImage} resizeMode='contain'>
... some content
</ImageBackground>图像以正确的方式呈现,但问题是它是垂直居中的,而不是我想让它顶部对齐……
This is an example of the result of my ImageBackground
This is an example of the result with the bottom added to ImageStyle
发布于 2018-12-11 22:20:31
在ImageBackground组件中,图像不是垂直居中的,而是绝对定位为填充容器。您可以查看源here。它显示为垂直居中的原因可能是因为resizeMode contain。要在顶部对齐它,您可以设置为属性imageStyle的用户,如下所示:
<ImageBackground
imageStyle={{
bottom: 40 // Whatever offset you want from the bottom
}}
/>https://stackoverflow.com/questions/53715334
复制相似问题