Difficulty: Medium
Correct Answer: A regular bitmap scales uniformly and may distort corners and edges, whereas a nine patch image has stretchable and non stretchable regions marked so that it can resize without distorting borders or key visual details.
Explanation:
Introduction / Context:
When designing Android user interfaces, developers often need images that can stretch to fit different screen sizes and text lengths while keeping borders and corners visually clean. This question checks whether you understand the role of nine patch images compared with simple bitmaps. Knowing the difference helps create scalable backgrounds and buttons without artefacts.
Given Data / Assumptions:
- Android uses bitmap resources for many visual elements, such as buttons and backgrounds.
- Some elements must stretch to accommodate different content sizes and screen densities.
- Standard scaling can distort important parts of an image if not controlled.
- Nine patch images provide a mechanism to control which parts stretch and which remain fixed.
Concept / Approach:
A regular bitmap is just a grid of pixels. When scaled, the entire image is resized uniformly, which can make borders blurry and corners distorted. A nine patch image is a specially prepared PNG file with one pixel wide black lines along its edges that define stretchable and content areas. The Android framework reads these markings and stretches only the marked regions while keeping corners and edges intact. This allows developers to design resizable backgrounds that look crisp at many sizes.
Step-by-Step Solution:
Step 1: Recall that nine patch images are created specifically to handle scalable UI elements.
Step 2: Identify an option that mentions stretchable and non stretchable regions.
Step 3: Option a explains that regular bitmaps scale uniformly and can distort, while nine patch images mark stretchable areas and preserve edges.
Step 4: Confirm that this matches Android documentation and typical design tutorials.
Step 5: Choose option a as the correct answer.
Verification / Alternative check:
To verify, imagine a chat bubble image used for message boxes. With a regular bitmap, enlarging the bubble to fit longer text will stretch the rounded corners and border lines unevenly. With a nine patch image, only the central area stretches while the corners remain smooth. Option a describes exactly this behaviour, confirming that it is correct.
Why Other Options Are Wrong:
Option b incorrectly ties the image types to device categories (mobile versus desktop), which is not how Android resources work. Option c talks about transparency differences, which are unrelated to the nine patch concept. Option d denies any functional difference, ignoring the stretch behaviour that is the core reason nine patch images exist.
Common Pitfalls:
Developers sometimes forget to define content padding correctly in nine patch images, which results in text being cut off or placed too close to borders. Another pitfall is creating overly complex nine patch regions that behave unpredictably when scaled. Testing nine patch images at different sizes and densities helps catch these problems early. Using the feature correctly leads to flexible and visually consistent user interfaces.
Final Answer:
A regular bitmap scales uniformly and may distort corners and edges, whereas a nine patch image has stretchable and non stretchable regions marked so that it can resize without distorting borders or key visual details.
Discussion & Comments