Skip to content
tezvyn:

What is the `res/` directory and how do you use resource qualifiers?

Source: developer.android.comEasyHow cards are made

What is the `res/` directory and how do you use resource qualifiers?

This tests your grasp of Android's resource system. Explain that res/ separates assets from code and that qualifiers (e.g., layout-land) let the OS pick the right layout. A red flag is checking orientation manually in code instead of using this system.

What's really being asked

Your knowledge of the core Android principle of separating application resources from code. It assesses if you understand how the system uses this separation to adapt the UI to different device configurations, like orientation, screen size, or language, without requiring manual logic in your code.

The full answer

First, the purpose of the res/ directory is to store all non-code assets, such as layouts (XML), images (drawables), strings, dimensions, and styles (values). This separation is key for maintainability and adaptation. Second, you should explain resource qualifiers. These are suffixes appended to resource directory names that specify the configuration for which those resources are designed. Third, for the portrait/landscape example, you would create two directories: res/layout/ for the default (portrait) layout file (e.g., activity_main.xml) and res/layout-land/ for the landscape version of the same file (activity_main.xml). The Android OS automatically selects and inflates the correct layout from either layout or layout-land when setContentView(R.layout.activity_main) is called, based on the device's current orientation.

The mistakes people make

The biggest red flag is suggesting you should check the device's orientation programmatically within your Activity's onCreate method and then use an if-else statement to call setContentView with different layout files. This is inefficient, error-prone, and completely ignores the powerful resource qualifier system built for this exact purpose. Another mistake is being vague, simply saying "it holds resources" without explaining why this separation is a cornerstone of Android development. Confusing the purpose of mipmap (for density-independent launcher icons) with drawable (for all other image assets) is also a minor flag.

What usually comes next

How would you provide different strings for English and Spanish users? (By creating res/values/strings.xml for the default and res/values-es/strings.xml for Spanish). What happens if you have a layout-sw600dp-land directory and a layout-land directory on a 7-inch tablet in landscape? (The system will choose the most specific matching qualifier, so layout-sw600dp-land would be used). How does this system help reduce APK size? (App Bundles use this resource information to generate split APKs, so a user's device only downloads the resources it needs, like xhdpi drawables, not all densities).

A concrete example

To create a screen with a button below a text view in portrait and next to it in landscape: res/layout/my_screen.xml would use a vertical LinearLayout. res/layout-land/my_screen.xml would use a horizontal LinearLayout. In both XML files, the views would have the same android:id. The Activity code remains simple: setContentView(R.layout.my_screen). The system handles selecting the correct file. No conditional logic is needed in the Kotlin/Java code.

Interview question

What is the standard practice for providing a different layout file for landscape orientation on Android?

  • a.Define a `<config-change>` attribute in `AndroidManifest.xml` that points to the landscape layout file.
  • b.In the Activity's `onCreate`, check the orientation and use an if-else block to call `setContentView()`.
  • c.Create a `res/layout-land/` directory and place a layout file inside it with the same name as the default.Correct
  • d.Place both layouts in `res/layout/` but with different names, like `main_port.xml` and `main_land.xml`.
Why?

Android's resource system automatically selects the correct layout by using directory name qualifiers. Creating a `layout-land` directory is the standard way to provide an alternative layout, which the system will use without requiring any conditional logic in your code.

Just read this? Test yourself on what you have been reading.

Read the original → developer.android.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.

See open roles