Search code examples
cssreact-nativemargin

marginTop create problems for subview


I have one view in which other image is there. when I give

marginTop:'10%' 

to view subview images is not displaying in that view. Any solution


Solution

  • In React-Native we have an Option called Dimensions (reference)

    and here's what I do :

    import Dimensions from 'Dimensions';
    [...]
    
    const DeviceWidth = Dimensions.get('window').width;
    class YourClass extends React.Component {
      //render and return
      //DeviceWidth*0.9 = 90%
      <View style={{marginTop: DeviceWidth*0.1}}></View>
    }
    

    give it a try