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可以決定布局的主軸。子元素是應該沿著水平軸(row)方向排列,還是沿著豎直軸(column)方向排列呢?默認值是豎直軸(column)方向。
    flexDirection: 'row',//豎直軸(column)
    //justifyContent可以決定其子元素沿著主軸的排列方式。子元素是應該靠近主軸的起始端還是末尾段分布呢?亦或應該均勻分布?對應的這些可選項有:flex-start、center、flex-end space-around以及space-between。
    justifyContent: 'flex-start',//flex-start、center、flex-end、space-around以及space-between
    //alignItems可以決定其子元素沿著次軸(與主軸垂直的軸,比如若主軸方向為row,則次軸方向為column)的排列方式。子元素是應該靠近次軸的起始端還是末尾段分布呢?亦或應該均勻分布?對應的這些可選項有: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,
  },
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容