当前位置:  开发笔记 > 编程语言 > 正文

ReactNative:如何在父视图中将元素放到右侧

如何解决《ReactNative:如何在父视图中将元素放到右侧》经验,为你挑选了1个好方法。



1> Nader Dabit..:

您可以使用flex-direction:row将detailBox项目包装在flexbox容器中,然后将flex:1设置为两个主要子组件:


  
    opened: {item.opened}
    closed: {item.closed}
  
  
    {item.status}
  

样式:

box1: {
  flex:1,
},
box2: {
  flex:1,
},
detailBox: {
  flexDirection: 'row'
}

我还成立了一个工作示例这里(代码如下所示).

https://rnplay.org/apps/_yOSHw

'use strict';

var React = require('react-native');
var {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  ListView,
  TouchableHighlight
} = React;

var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
var data = [{name: 'issue 1', opened: '2 days ago', closed: 'a day ago', status: 'CLOSED'}, {name: 'issue 2', opened: '10 days ago', closed: '3 days ago', status: 'CLOSED'}]

var SampleApp = React.createClass({

  getInitialState() {
    return {
        dataSource: ds.cloneWithRows(data),
    };
  },

  renderItems(item) {
      return (
           this.showItemDetail(item)}  underlayColor='#dddddd' #fffce2', borderBottomWidth:1, borderBottomColor: '#ededed' }}>
              
                  
                      
                          {item.name}
                          
                              
                                  opened: {item.opened}
                                  closed: {item.closed}
                              
                              
                                  {item.status}
                              
                          
                      
                  
                  
              
          
      );
  },

  render: function() {
    return (
      
        
      
    );
  }
});

var styles = StyleSheet.create({
  container: {
    flex: 1,
    marginTop:60,
  },
  status: {
    textAlign: 'center',
    paddingRight:20,
    color: 'red', 
    fontSize:18
  },
  box1: {
    flex:1,
    padding:10
  },
  box2: {
    flex:1,
    padding:10
  },
  title: {
    fontSize:18,
    paddingTop:10, 
    paddingLeft:10
  },
  detailBox: {
    flexDirection: 'row'
  },
  separator: {

  }
});

AppRegistry.registerComponent('SampleApp', () => SampleApp);

推荐阅读
吻过彩虹的脸_378
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有