【发布时间】:2017-06-06 13:56:27
【问题描述】:
我是 flexbox 样式的新手。我在尝试将 flexbox 中的元素对齐到最右角时遇到问题。我编写了以下代码将图像中的加号对齐到红色框的右上角,但它没有按预期工作。请帮我解决这个问题。
<View style={main_container}>
<ScrollView>
<TouchableHighlight>
<View style={container}>
<Image style={imageStyle} source={{uri: this.props.data.picture}} />
<Text style={textStyle}> {this.props.data.company} </Text>
<Text style={iconStyle}>
<Icon name={'plus-circle'} size={20} color={'#003057'} />
</Text>
</View>
</TouchableHighlight>
</ScrollView>
<Footer />
</View>
const styles = StyleSheet.create({
main_container: {
flex: 1,
flexDirection: 'column',
marginTop: 70
},
container: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
margin: 6,
backgroundColor: 'red'
},
imageStyle: {
width: 50,
height: 50
},
textStyle: {
fontSize: 10
},
iconStyle: {
backgroundColor: 'yellow',
alignSelf: 'flex-end' //why is it aligning the image vertically ?
}
});
【问题讨论】:
-
margin-left: auto- 这会将它推到右边 -
嘿@pol,react native 没有 marginLeft: auto,我想知道 alignSelf: 'flex-end' 有什么问题。
-
margin-left: "auto" 工作不要忘记 ""
标签: css react-native flexbox