我正嘗試在我的反應原生應用中調整圖片大小(較小以適合屏幕),但無法做到這一點,因爲它太大了。在React Native中調整圖片大小
下面是代碼:
'use strict';
var React = require('react-native');
var {
StyleSheet,
Text,
TextInput,
View,
TouchableHighlight,
ActivityIndicatorIOS,
Image,
Component
} = React;
var styles = StyleSheet.create({
description: {
marginBottom: 20,
fontSize: 18,
textAlign: 'center',
color: '#656565'
},
container: {
padding: 30,
marginTop: 65,
alignItems: 'center'
},
flowRight: {
flexDirection: 'row',
alignItems: 'center',
alignSelf: 'stretch'
},
buttonText: {
fontSize: 18,
color: 'white',
alignSelf: 'center'
},
button: {
height: 36,
flex: 1,
flexDirection: 'row',
backgroundColor: '#48BBEC',
borderColor: '#48BBEC',
borderWidth: 1,
borderRadius: 8,
marginBottom: 10,
alignSelf: 'stretch',
justifyContent: 'center'
},
searchInput: {
height: 36,
padding: 4,
marginRight: 5,
flex: 4,
fontSize: 18,
borderWidth: 1,
borderColor: '#48BBEC',
borderRadius: 8,
color: '#48BBEC'
},
image: {
width: 200,
height: 220
},
});
class SearchPage extends Component {
render() {
return (
<View style={styles.container}>
<Image source={require('image!rclogo')} style={styles.image}/>
<Text style={styles.description}>
Search for RCers!
</Text>
<Text style={styles.description}>
Search
</Text>
<View style={styles.flowRight}>
<TextInput
style={styles.searchInput}
placeholder='Search by Batch, Name, Interest...'/>
<TouchableHighlight style={styles.button}
underlayColor='#99d9f4'>
<Text style={styles.buttonText}>Go</Text>
</TouchableHighlight>
</View>
<TouchableHighlight style={styles.button}
underlayColor='#99d9f4'>
<Text style={styles.buttonText}>Location</Text>
</TouchableHighlight>
</View>
);
}
}
我試圖把它拿出來的集裝箱電子標籤的,但似乎無法理解爲什麼它不能正常顯示?
這可以通過flexbox resizeMode完成嗎?你怎麼做呢?我找不到任何文檔...
這應該是工作。將寬度更改爲100時什麼都不會發生? 另請參閱https://github.com/facebook/react-native/blob/master/Libraries/Image/Image.ios.js以獲取有關可用屬性的更多信息。 –
你試過'resizeMode:'cover''嗎? – amit
是啊'resizeMode:'cover''沒有任何反應。 –