7,React Native 之Flexbox布局

1,來張分析圖

Paste_Image.png

組件

  <View style={styles.views}>
          <View style={styles.view1}></View>
          <View style={styles.view2}></View>
          <View style={styles.view3}></View>
   </View>

樣式,在const styles = StyleSheet.create({});方法寫

views:{
    flex:1,
    backgroundColor: '#DCDCDC',
    //flexDirection可以決定布局的主軸。子元素是應(yīng)該沿著水平軸(row)方向排列,還是沿著豎直軸(column)方向排列呢?默認(rèn)值是豎直軸(column)方向。
    flexDirection: 'row',//豎直軸(column)
    //justifyContent可以決定其子元素沿著主軸的排列方式。子元素是應(yīng)該靠近主軸的起始端還是末尾段分布呢?亦或應(yīng)該均勻分布?對應(yīng)的這些可選項(xiàng)有:flex-start、center、flex-end space-around以及space-between。
    justifyContent: 'flex-start',//flex-start、center、flex-end、space-around以及space-between
    //alignItems可以決定其子元素沿著次軸(與主軸垂直的軸,比如若主軸方向?yàn)閞ow,則次軸方向?yàn)閏olumn)的排列方式。子元素是應(yīng)該靠近次軸的起始端還是末尾段分布呢?亦或應(yīng)該均勻分布?對應(yīng)的這些可選項(xiàng)有:flex-start、center、flex-end以及stretch。
    alignItems: 'center',//flex-start、center、flex-end以及stretch。
  },
  view1:{
    // flex:1,
    width:100,//Dimensions.get('window').width
    backgroundColor:'plum',
    height:100,
  },
  view2:{
    // flex:1,
    backgroundColor:'paleturquoise',
    height:100,
    width:100,
  },
  view3:{
    // flex:1,
    backgroundColor:'palegoldenrod',
    height:100,
    width:100,
  },
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容