If two nested child views both have flex: 1 , they will split the parent's space equally (50/50). 3. justifyContent and alignItems
As you continue your coding journey on CodeHS, remember to think in terms of boxes inside boxes. Start with a single parent container, break the screen into regions using nested View components, and then fill those regions with content. With practice and attention to Flexbox principles, you will go from struggling with the 2.3.9 exercise to building your own fully functional mobile apps in no time.
<!-- These views are inside the nested layout --> <TextView ... /> <TextView ... />
Keep related elements (like an avatar image and a username text) tied together so they move as a single unit.
Think of it like a cardboard box (parent) holding smaller plastic bins (children), which in turn hold your actual items like text or images. Why Use Nested Views? 2.3.9 nested views codehs
);
If you are working through the CodeHS Web Development curriculum (specifically the JavaScript or Graphics track), you have likely encountered the exercise . At first glance, this problem can seem daunting. You are asked to arrange visual elements inside other visual elements, manage coordinates, and keep everything responsive.
In the CodeHS exercise 2.3.9, the goal is typically to add a TextView inside a specific container to demonstrate this nesting capability.
const styles = StyleSheet.create( container: flex: 1, justifyContent: 'center', alignItems: 'center', , parentBox: backgroundColor: 'blue', height: 200, width: 200, // Aligns the nested child inside this box justifyContent: 'center', alignItems: 'center', , childBox: backgroundColor: 'red', height: 100, width: 100, , ); Use code with caution. Copied to clipboard 2. Structure the Components If two nested child views both have flex:
A single vertical LinearLayout can’t handle the "[ Text A ] [ Text B ]" row. It can stack them vertically, but not place them side-by-side.
: Centers the entire project on the screen using justifyContent: 'center' and alignItems: 'center' . styles.outerBox : Creates a 200×200 green square.
In CodeHS, nested views refer to the ability to place one view inside another. This is a powerful feature that allows for more complex and organized user interfaces.
Child position = Parent position + Offset. Start with a single parent container, break the
Now go ahead, nest those views, and watch your UI come to life!
In CSS, if a parent has position: relative , a child with position: absolute will be positioned relative to the parent—not the whole page. This is a powerful nesting technique.
You can style the parent to hold the overall structure, while the children hold individual UI elements.