我知道React Native中有一个类似于Android VieGroup的“视图”组件,它更像线性布局一样工作-子级按行或列排列。
我想知道如何实现“ FrameLayout”行为-子项堆叠在布局中,并且可以为每个子项分配唯一的重力位置。
例如:将5个子项放到一个组件中,这4个子项中的每一个均与布局的每个角对齐,最后一个子项与布局的中心对齐。
如何编写React Native的``渲染''功能?
可以使用position:'absolute'并将其顶部,左侧,右侧,底部属性对齐。这是一个工作样本
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
} = React;
var SampleApp = React.createClass({
render: function() {
return (
<View style={styles.container}>
<Text style={styles.topLeft}> Top-Left</Text>
<Text style={styles.topRight}> Top-Right</Text>
<Text>Center</Text>
<Text style={styles.bottomLeft}> Bottom-Left</Text>
<Text style={styles.bottomRight}> Bottom-Right</Text>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
marginTop: 24
},
topLeft:{
position: 'absolute',
left: 0,
top: 0
},
topRight:{
position: 'absolute',
right: 0,
top: 0
},
bottomLeft:{
position: 'absolute',
left: 0,
bottom: 0
},
bottomRight:{
position: 'absolute',
right: 0,
bottom: 0
}
});
AppRegistry.registerComponent('SampleApp', () => SampleApp);
同样在rnplay上,https: //rnplay.org/apps/n6JJHg
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句