100% width in React Native Flexbox

后端 未结 10 915
日久生厌
日久生厌 2020-12-12 11:51

I have already read several flexbox tutorial, but I still cannot make this simple task to work.

How can I make the red box to 100% width?

Code:

10条回答
  •  無奈伤痛
    2020-12-12 12:44

    First add Dimension component:

    import { AppRegistry, Text, View,Dimensions } from 'react-native';
    

    Second define Variables:

    var height = Dimensions.get('window').height;
    var width = Dimensions.get('window').width;
    

    Third put it in your stylesheet:

    textOutputView: {
        flexDirection:'row',
        paddingTop:20,
        borderWidth:1,
        borderColor:'red',
        height:height*0.25,
        backgroundColor:'darkgrey',
        justifyContent:'flex-end'
    }
    

    Actually in this example I wanted to make responsive view and wanted to view only 0.25 of the screen view so I multiplied it with 0.25, if you wanted 100% of the screen don't multiply it with any thing like this:

    textOutputView: {
        flexDirection:'row',
        paddingTop:20,
        borderWidth:1,
        borderColor:'red',
        height:height,
        backgroundColor:'darkgrey',
        justifyContent:'flex-end'
    }
    

提交回复
热议问题