【问题标题】:React Native Flexbox stacking view over each otherReact Native Flexbox 相互堆叠视图
【发布时间】:2018-10-26 14:25:58
【问题描述】:

如何将这 3 个盒子一个一个叠放?

我尝试设置所有这些但没有帮助 justifyContent: 'center', alignContent: 'center',alignSelf: 'center'

代码:

import React, { Component } from 'react';
import { AppRegistry, View } from 'react-native';

export default class FlexDirectionBasics extends Component {
  render() {
    return (
      // Try setting `flexDirection` to `column`.
      <View style={{  flex: 1, flexDirection: 'row' ,alignItems: 'center' ,
        justifyContent: 'center', alignContent: 'center',alignSelf: 'center'}}>
        <View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} />
        <View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} />
        <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />
      </View>
    );
  }
};

// skip this line if using Create React Native App
AppRegistry.registerComponent('AwesomeProject', () => FlexDirectionBasics);

【问题讨论】:

    标签: reactjs flexbox native


    【解决方案1】:

    使用right 属性将View 重叠到另一个上。

    <View style={{  flex: 1, flexDirection: 'row' ,alignItems: 'center', justifyContent: 'center', alignContent: 'center', alignSelf: 'center'}}>
      <View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} />
      <View style={{width: 50, height: 50, backgroundColor: 'skyblue', right: 20}} />
      <View style={{width: 50, height: 50, backgroundColor: 'steelblue', right: 30}} />
    </View>
    

    注意: 如果您想以不同的方式制作它,请告诉我。

    【讨论】:

    猜你喜欢
    • 2023-03-31
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 2021-04-30
    相关资源
    最近更新 更多