加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React Native-FlexBox布局

发布时间:2020-12-15 03:25:26 所属栏目:百科 来源:网络整理
导读:class FlexBoxDemo extends Component { render() { return( View style={flexBoxStyle.flexBoxStyle} Text style={{width: 50,height: 50,backgroundColor: 'red',flex: 1}}Text1/Text Text style={{width: 50,backgroundColor: 'green',flex: 1}}Text2/Tex
class FlexBoxDemo extends Component {
  render() {
    return(
        <View style={flexBoxStyle.flexBoxStyle}>
          <Text style={{width: 50,height: 50,backgroundColor: 'red',flex: 1}}>Text1</Text>
          <Text style={{width: 50,backgroundColor: 'green',flex: 1}}>Text2</Text>
          <Text style={{width: 50,backgroundColor: 'yellow',flex: 2}}>Text3</Text>
          {/*flex属相相当于Android中的权重就是所在父控件的比例比如Text4占父控件的七分之三
           alignSelf熟悉是相对于父控件的位置auto,center,flex-end,flex-start,stretch和alignItems属相意思相同*/}
          <Text style={{width: 50,backgroundColor: 'blue',flex: 3,alignSelf: 'flex-end'}}>Text4</Text>
        </View>
    );
  }
}

const flexBoxStyle = StyleSheet.create({
  flexBoxStyle: {
    marginTop: 20,flex: 1,//row,column,横向和竖向
    flexDirection: 'row',//space-between(两端固定),flex-start(固定在开始),flex-end(固定在结束),// center(固定在中间),space-around(两端大约是其它平分空间的二分之一)
    justifyContent: 'space-around',//flex-start(子控件在父控件的开始),flex-end(子控件在父控件的结束位置),center(子控件在中间),stretch(拉伸),alignItems: 'stretch',},});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读