reactjs - 使用具有 2 个组件但都不相邻的 flexbox
问题描述
图片在这里。
我只想要靠近 Weather 组件的 Advice 组件。我怎么才能得到它 ?
应用程序.js
<View style={styles.columnLayout}>
<Weather currentCity="Phuket"/>
<Advice />
</View>
const styles = StyleSheet.create({
columnLayout : {
flex : 1,
flexDirection: 'column',
}
})
Weather 和 Advice 组件没有使用 flex。
WeatherData.js(导出到 Weather.js)
<View style={styles.viewStyle}>
<View style={styles.dataStyle}>
<Text style={styles.textStyle}>Temperature</Text>
<Text style={styles.textStyle}>{this.props.temp} °C</Text>
</View>
<View style={styles.dataStyle}>
<Image style={{ width: 80, height: 80 }} source={{ uri: `http://openweathermap.org/img/w/${this.props.icon}.png` }}></Image>
<Text style={styles.textStyle}>{this.props.description}</Text>
</View>
<View style={styles.dataStyle}>
<Text style={styles.textStyle}>Humidity</Text>
<Text style={styles.textStyle}>{this.props.humidity} %</Text>
</View>
</View>
const styles = StyleSheet.create({
dataStyle: {
backgroundColor: '#00b377',
flex: 1,
alignItems: "center",
justifyContent: "center"
},
viewStyle: {
height: 150,
flexDirection: "row",
justifyContent: "center"
},
textStyle: {
color: 'white',
textShadowColor: 'rgba(0, 0, 0, 0.75)',
textShadowOffset: {width: -1, height: 1},
textShadowRadius: 10
}
})
另一个使用相同样式的组件。
解决方案
我已经添加了代码。在 react-native 文档中 flex : 1 和 flexDirection : column 所有视图都是相邻的,但我的不是。
推荐阅读
- html - 为什么 CSS position: sticky 不适用?
- python - 防止 PyCharm 在远程 Docker 解释器中覆盖 PYTHONPATH
- xpath - 如何从特定元素获取 href 标签中的链接
- javascript - 在一个 MongoDb 连接中执行多个提交
- java - 随机 4 个小于最大最大值(例如 100_000)的唯一整数的有效算法
- javascript - 是否可以显示带有 url 的 div?
- java - 与微服务和 Gradle 一起使用的 Spring Boot 多模块
- javascript - 如何将 HTMLDocument 元素添加到 StencilJS 组件的 JSX 模板
- ios - 无法在 Xamarin.Forms iOS 项目中关闭 iOS toast 警报消息
- angular - ngClass - 从变量中应用多个类?