How to achieve 'FrameLayout' component in React Native?

后端 未结 2 475
北恋
北恋 2021-01-18 01:58

I know there is a \'View\' component in React Native that acts like Android VieGroup, how ever it is more likely to work as LinearLayout - childrens are arranged in rows or

2条回答
  •  难免孤独
    2021-01-18 02:06

    That can be done using position: 'absolute' and align it top,left,right,bottom properties. Here is an working sample

    'use strict';
    
    var React = require('react-native');
    var {
      AppRegistry,
      StyleSheet,
      Text,
      View,
    } = React;
    
    var SampleApp = React.createClass({
      render: function() {
        return (
          
                     Top-Left
                     Top-Right
            Center
             Bottom-Left
             Bottom-Right
          
        );
      }
    });
    
    var styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
        marginTop: 24
      },
      topLeft:{
        position: 'absolute',
        left: 0,
        top: 0
      },
        topRight:{
        position: 'absolute',
        right: 0,
        top: 0
      },
        bottomLeft:{
        position: 'absolute',
        left: 0,
        bottom: 0
      },
        bottomRight:{
        position: 'absolute',
         right: 0,
        bottom: 0
      }
    });
    
    AppRegistry.registerComponent('SampleApp', () => SampleApp);
    

    Also on rnplay, https://rnplay.org/apps/n6JJHg

提交回复
热议问题