top of page

2.3.9 Nested Views Codehs 【DELUXE】

If you’ve been working through the Android unit in CodeHS, you’ve likely gotten comfortable with simple layouts. You know how to plop a TextView here or a Button there. But what happens when you need to build a complex screen—like a profile card with an image, a name, and a status side-by-side?

That is where Nested Views come in.

In this post, we are breaking down CodeHS Exercise 2.3.9: Nested Views. We will explain why nesting is necessary, how the XML structure works, and how to solve the specific challenge of placing a TextView inside a LinearLayout. 2.3.9 nested views codehs


In the context of the CodeHS Graphics library (often based on Tab or View classes), a nested view refers to a user interface element (a "View") that contains other views inside it.

Think of it like Russian nesting dolls or a file system on your computer: If you’ve been working through the Android unit

While CodeHS problems vary slightly by year, the standard prompt for 2.3.9 Nested Views usually reads something like:

Create a main view (parent). Inside it, create two or three smaller views (children). Each child view should have its own background color and border. Add a text label inside one of the child views. The layout should resemble a dashboard or a settings screen. In the context of the CodeHS Graphics library

Here is an example of nested views in CodeHS using JavaScript:

// Create the main view
var mainView = new View(0, 0, 400, 400);
// Create a sub-view
var subView = new View(50, 50, 300, 300);
// Add the sub-view to the main view
mainView.add(subView);
// Set the background color of the sub-view
subView.setBackgroundColor('lightblue');
// Create a button and add it to the sub-view
var button = new Button(100, 100, 100, 50, 'Click me!');
subView.add(button);
// Add the main view to the screen
addView(mainView);
bottom of page