如何在React Native的另一个视图中居中视图?

Mil*_*mak 19 flexbox react-native

我想在React Native中将一个视图置于另一个视图中.

这是我的代码:

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'column',
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'yellow',
  },
  outerCircle: {
    backgroundColor: 'blue',
    width: 100,
    height: 100,
    borderRadius: 100/2,
  },
  innerCircle: {
    backgroundColor: 'red',
    width: 80,
    height: 80,
    borderRadius: 80/2,
  }
});

export default class RecorderButton extends React.Component {

  _buttonPressAction() {
    Alert.alert("button pressed");
  }

  render() {
    return (
      <TouchableOpacity activeOpacity={0.4}
                        onPress={this._buttonPressAction}
                        style={styles.container}>
        <View style={styles.outerCircle}>
          <View style={styles.innerCircle} />
        </View>
      </TouchableOpacity>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

这就是它的样子: 非中心-cirlces

我希望蓝色和红色圆圈同心.我如何实现这一目标?

age*_*unt 38

你已经集中在容器中了.对于outerCircle也是如此.

  outerCircle: {
    backgroundColor: 'blue',
    width: 100,
    height: 100,
    borderRadius: 100/2,
    justifyContent: 'center',
    alignItems: 'center'
  },
Run Code Online (Sandbox Code Playgroud)


she*_*han 11

通过以下两条使事情成为中心

justifyContent:'中心',alignItems:'中心',