所以我在 react native 中设置背景图像,但我需要将背景图像的位置设置为底部。所以如果有人知道如何实现这一点。
我曾尝试添加 backgroundPosition 但它似乎不受支持
<ImageBackground
source={require("../assets/img/bg-top.png")}
// resizeMethod={'auto'}
style={{
width: "100%",
height: 120,
padding: 20,
paddingVertical: 40,
backgroundPosition: "bottom" // not working
}}
imageStyle={{
resizeMode: "cover",
alignSelf: "flex-end"
}}
>
<Text style={{ color: "#D8D8D8", fontSize: 16 }}>Login</Text>
</ImageBackground>;
我希望图像对齐应该从底部开始,而不是从顶部开始
最佳答案
React Native 提供 底部和 职位标记以在底部设置 UI。请将 backgroundPosition 标签从图像样式替换为
位置:'绝对',
底部:0
<ImageBackground
// resizeMethod={'auto'}
style={{
width: "100%",
height: 120,
backgroundColor:'#000',
padding: 20,
paddingVertical: 40,
position: 'absolute',
bottom:0
}}
imageStyle={{
resizeMode: "cover",
alignSelf: "flex-end"
}}
>
<Text style={{ color: "#D8D8D8", fontSize: 16 }}>Login</Text>
</ImageBackground>
请检查小吃博览会
https://snack.expo.io/@vishal7008/bottom-ui
关于react-native - 如何在 React Native 中设置 `ImageBackground` 图像位置。就像在 css `background-postion: bottom` 中一样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55673291/