React Native中的Absolute和Flexbox

ila*_*sas 76 javascript css react-native

我想放一个白色条,它会占据屏幕底部的所有宽度.为此,我考虑使用absolute继承flexbox参数的定位.

随着下面的代码它呈现像这样.

这是我的代码:

var NavigationBar = React.createClass({
  render: function() {
    return(
    <View style={navigationBarStyles.navigationBar}>
      //Icon 1, Icon 2...
    </View>
    );
  }
});

var Main = React.createClass({
  render: function() {
    return(
      <View style={mainStyles.container}>
          <NavigationBar />
      </View>
    );
  }
});

var mainStyles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#456783',
  }
});

var navigationBarStyles = StyleSheet.create({
  navigationBar: {
    backgroundColor: '#FFFFFF',
    height: 30,
    position: 'absolute', 
    flexDirection: 'row',
    bottom: 0,
    justifyContent: 'space-between'
  },
});
Run Code Online (Sandbox Code Playgroud)

我是CSS中的样式新手,并不是React-Native中提供的所有属性.所以任何帮助都表示赞赏,谢谢:)

ila*_*sas 131

好的,解决了我的问题,如果有人路过这里就是答案:

只是必须添加left: 0,top: 0,风格,是的,我很累.

position: 'absolute',
left:     0,
top:      0,
Run Code Online (Sandbox Code Playgroud)

  • 感谢发布.而且看起来同样是高度 - 而不是'高度:100%`,做顶部:0,底部:0`. (10认同)
  • 但是如果你想把条形图放在底部和全宽,你应该添加`left:0,right:0`,并且不应该添加`top:0`,如果你设置`top:0`和`bottom: 0`,它将全屏显示. (3认同)

Spa*_*Bao 50

第一步是添加

position: 'absolute',
Run Code Online (Sandbox Code Playgroud)

那么如果你想要元素全宽,请添加

left: 0,
right: 0,
Run Code Online (Sandbox Code Playgroud)

然后,如果你想把元素放在底部,添加

bottom: 0,
// don't need set top: 0
Run Code Online (Sandbox Code Playgroud)

如果要将元素放在顶部,请替换bottom: 0top: 0