我有这样的图像:
我正在尝试制作一个 100x100 的正方形,然后将该图像居中。我可以使用以下代码获得 100x100 的正方形:
import * as React from 'react';
import { View, Image, StyleSheet } from 'react-native';
class App extends React.Component {
render() {
return (
<View style={styles.container}>
<View style={styles.imageContainer}>
<Image
source={{ uri: 'https://storage.googleapis.com/iex/api/logos/GOOGL.png', }}
style={styles.image}
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
imageContainer: {
borderWidth: 1
},
image: {
width: 100,
height: 100
}
});
export default App;
但是,这会切断图像:
有没有办法可以设置 100x100 的宽度/高度,但允许图像根据需要调整大小以适合并在正方形内居中?谢谢!