我有一些代码可以将随机大小的图像扩展到容器的整个宽度+在容器内部垂直居中。但是我需要将其锚定在顶部。
在CSS中,我会使用背景位置,但是React Native不支持它。我觉得我已经尝试过resizeMode,绝对定位等的每种组合-但仍然无法弄清楚。
<View style={{
flex: 1,
height: 120,
}}>
<Image source={{uri: source}} style={{
flex: 1,
width: '100%',
resizeMode: 'cover'
}}>
</Image>
</View>
Run Code Online (Sandbox Code Playgroud)
Sye*_*Ali -1
return (
<View
style={{
flex: 1,
height: 120,
justifyContent: "center",
alignContent: "center"
}}
>
<TouchableOpacity onPress={() => alert("Hello ")}>
<Text style={{ alignSelf: "center" }}>Anchor Tag</Text>
</TouchableOpacity>
<Image
source={{
uri: "https://shoutem.github.io/img/ui-toolkit/examples/image-3.png"
}}
style={{
width: "100%",
height: 100,
resizeMode: "cover"
}}
/>
</View>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
882 次 |
| 最近记录: |