React Native Set View Width Height in Fixed Dimensions Android iOS

How to apply custom height and width in pixels in react native android iOS application using custom style sheet on both parent and child View Fixed Dimensions.

Fixed height and width gives the View to a permanent area on screen no matter what screen size is. We can define fixed height using style. All we have to do is define View’s Height using height and Width using width in style. If will cover the screen according to given size because all dimensions in React Native are unitless with density independent pixels.

Contents in this project Set View Width Height in Fixed Dimensions :

  1. Start a fresh React Native project. If you don’t know how then read my this tutorial.
  2. Add StyleSheet and View component in import block.
  3. Add Singe View as parent view in render’s return block.
  4. Add Three different View inside the Parent View.
  5. Add inline Style for all three Children View.
  6. Add height and width in pixels in Style.
  7. Complete Source Code.

1. Start a fresh React Native project. If you don’t know how then read my this tutorial.

2. Add StyleSheet and View component in import block.

3. Add Singe View as parent view in render’s return block.

4. Add Three different View inside the Parent View.

5. Add inline Style for all three Children View.

6. Add height and width in pixels in Style.

7. Complete Source Code for index.android.js file :

Screenshot in iOS device :

Fixed Dimensions

Screenshot in Android device :

4 Comments

  1. Hello,

    I have created some demo apps with help of your code available on same site with my additional coding, but i facing the problem of responsiveness in different screen size devices and in orientations too, please help me to make this apps works properly or same for all devices.

    • Rohit to make responsive width and height you need to declare height and width in percentage format like width : ‘50%’. This would works on both orientations.

  2. Shishir Aithal

    Hello,

    I have created some demo apps where the tool bar is coming from android and the rest content page is in react-native, now since the tool bar is from android studio am unable to fix the content page height dynamically to each different devices (even after giving height in percentage structure because that tool bar from android takes different height in each different device). What is the workaround i could do to over come this problem?

    • You need to use react native’s own Toolbar using activity structure using React Navigation, we have almost every tutorial regarding to react navigation on our website so just search on the search box bro 🙂 .

Leave a Reply

Your email address will not be published.