Android User Interface(UI)

The Android User Interface plays a vital role in determining how users interact with your application. A clean, responsive, and intuitive user interface (UI) can make your app stand out in a crowded marketplace.

This guide will help you understand the building blocks of Android UI and also cover key concepts like screen size, resolution, dp vs sp, orientation handling, and supporting multiple screens effectively.

🧩 What is Android User Interface?

The User Interface (UI) is the front face of your app — the part users see and interact with. In Android, UI is mainly built using XML layouts to define structure and Java/Kotlin to add behavior.

Android’s UI system consists of:

  • Views (like buttons, text fields)
  • ViewGroups (like layouts)
  • Styling & Themes
  • Resources (strings, colors, dimensions)
  • Animations
  • Support for multiple screen sizes & orientations

Screen size

  • Screen size refers to the diagonal length of a device’s display area, measured in inches (“) from corner to corner.
  • In android, it groups all screen sizes in 4  generalized sizes i.e small, medium, large and extra large.

Example: A “6.7-inch phone” means its screen diagonal is 6.7 inches long.

Density Pixel (dp)

  • dp (or density-independent pixel) is a unit of measurement used to make sure your app’s layout looks the same size on all screen sizes and densities.
  • It helps your UI look consistent, no matter the phone or tablet.

Screen Density

  • Screen density refers to the number of pixels within a physical area of the screen (measured in dpi – dots per inch).
  • It affects how content appears: too small, too big, or just right.

📌 A phone with more pixels per inch (higher density) shows sharper images.

Density NameAbbreviationDPI Range
Lowldpi~120 dpi
Mediummdpi~160 dpi (baseline)
Highhdpi~240 dpi
Extra Highxhdpi~320 dpi
XX Highxxhdpi~480 dpi
XXX Highxxxhdpi~640 dpi

Density Independence

Density independence means that your app’s UI looks the same physical size on all screens, no matter how many pixels those screens have.

Why is density independence important?

  • Phones and tablets come with different screen densities:
    • Some have few pixels per inch (low density)
    • Some have many pixels per inch (high density)
  • Without density independence:
    • A button that looks perfect on one phone may look tiny or huge on another.

Important as it makes sure UI elements (like buttons, images, and text) look consistent in size across all screen types.

Scale-independent pixels (sp)

  • It’s just like dp, but with extra support for user font size preferences.

Why use sp?

It is used to make sure that:

  • Your text sizes stay readable on all screen sizes
  • Your app respects the user’s accessibility settings (e.g., larger font for poor vision)

dp vs sp

UnitScales with screen density?Scales with user’s font size setting?Use it for?
dp✅ Yes❌ NoLayout sizes, padding
sp✅ Yes✅ YesText sizes

Resolution

  • Resolution is the total number of pixels on a screen.
  • Pixels are the tiny dots that make up everything you see on your screen — text, images, videos, and apps.

For example, 1920×1080 means the screen is 1920 pixels wide and 1080 pixels tall

At Glance

TermMeans
PixelOne tiny dot on the screen
ResolutionTotal number of pixels
High resolutionMore pixels = more detail and space
Low resolutionFewer pixels = less detail

Importance of Screen & Orientation Adaptation

  • Fragmentation: 3,000+ Android devices with varying screen densities (e.g., mdpi, hdpi, xxhdpi).
  • User Behavior: 40% of users rotate devices for videos, forms, or gaming.
  • App Store Rejections: Poorly optimized layouts can lead to negative reviews or rejection.

📱 1. Fragmentation: 3,000+ Android Devices

There are thousands of Android devices from different manufacturers like Samsung, Xiaomi, Oppo, OnePlus, etc. Each of them can have:

  • Different screen sizes (small phones to large tablets)
  • Different resolutions (HD, Full HD, 2K, etc.)
  • Different screen densities like:
    • mdpi (160dpi) – medium
    • hdpi (240dpi) – high
    • xhdpi (320dpi) – extra high
    • xxhdpi (480dpi) – super high

Why it matters?
You can’t design a fixed-size layout for one phone and expect it to look the same on all devices. For example:

  • A button may look perfect on a Samsung Galaxy A52 (xxhdpi), but too small on a low-end device with mdpi.

🔄 2. User Behavior: 40% of Users Rotate Devices

Almost 4 out of 10 users rotate their devices to landscape mode:

  • While watching videos
  • Filling long forms or reading documents
  • Playing games

Why it matters:
If your layout doesn’t adapt well to orientation change, it might:

  • Look broken (e.g., overlapping text or buttons off-screen)
  • Reset form fields if not handled properly
  • Crash the app if resources are not correctly managed

🚫 3. App Store Rejections or Negative Reviews

If your app’s UI:

  • Looks bad on some screen sizes or densities
  • Doesn’t support rotation properly
  • Has buttons that are too small or texts that are too large…

…users may leave bad reviews or uninstall the app. Worse, Google Play Store may reject poorly optimized apps that don’t follow their design guidelines.

Why it matters:

  • Negative reviews affect downloads and ratings
  • Users may complain: “UI not responsive”, “Text cuts off”, “Buttons overlap”
  • App store policies emphasize accessibility, scalability, and compatibility
FactorRiskSolution
FragmentationUI may look different or broken on devicesUse dp, scalable layouts, and test thoroughly
Orientation UseLayout may crash or resetHandle orientation changes and save state
Poor UINegative reviews or Play Store rejectionFollow best practices, use modern layout tools

Orientation

Orientation is the direction your device is held.

OrientationDescription
📱 PortraitVertical (tall) – default orientation
🖼️ LandscapeHorizontal (wide) – turned sideways

🔄 When the Device Rotates (Portrait ↔ Landscape)

1. The screen size and shape change

  • In portrait mode, the screen is taller.
  • In landscape mode, the screen is wider.
  • This change affects how UI elements fit on the screen.

🟢 Example: A vertical list might look fine in portrait, but feel squished or stretched in landscape.

2. Layout might look broken or crowded

  • If the layout isn’t responsive:
    • Text might get cut off
    • Buttons might overlap
    • Images might not resize properly

🛑 Example: A form with many fields may not fit in landscape if scrolling or resizing isn’t handled.

3. You may want to show a different UI design

  • Some apps provide separate layouts for portrait and landscape.
  • Landscape may show:
    • Split view (e.g., list on left, details on right)
    • Larger previews
    • More info side-by-side

🖥 Example: Video apps usually hide toolbars in landscape for full-screen viewing.

Multiple Screen

Android runs on devices of:

  • Different screen sizes 📏 (small phone, tablet, foldable)
  • Different resolutions 🖼️ (HD, Full HD, etc.)
  • Different densities 📐 (mdpi, hdpi, xhdpi…)

👉 Your app should look and work well on all of them.

Best Practices to Support Multiple Screens(Make the app responsive)

1. 📐 Use dp and sp Units

  • Use dp (density-independent pixels) for layout sizes and margins
  • Use sp (scale-independent pixels) for text sizes

✅ Ensures consistent size across different screen densities

2. 📁 Provide Alternative Resources

🖼️ For Images: Use different drawable folders.

  • drawablemdpi     → for medium density (baseline)
  • drawablehdpi    → for high density
  • drawablexhdpi    → for extrahigh density
  • drawablexxhdpi   → for very high density

📐 For Layouts: Use alternative layout folders.

  • layout/            → default layout
  • layout-sw600dp/    → for 7″ tablets
  • layout-sw720dp/    → for 10″ tablets
  • layout-land/       → for landscape orientation
  • layout-port/       → for portrait (optional)

3. 🧭 Use Responsive Layouts

Use layouts like:

  • ConstraintLayout → flexible and powerful
  • LinearLayout with layout_weight → distributes space
  • Avoid hard-coded width and height

✅ Makes UI elements adjust to available space

4. 🔄 Handle Orientation Changes

  • Use layout-land for a different layout in landscape
  • Avoid fixed-width UI elements that break when rotated
  • Use onSaveInstanceState() , if you need to keep data during rotation

User Interface classes

  • User Interface (UI) classes are a part of the Android SDK used to build the visual components that users interact with. 
  • Building Blocks for App Interfaces
  • These classes belong mainly to the android.view and android.widget packages.

Important UI classes in Android:

  1. View Class
  2. ViewGroup Class
Android User Interface

1. View Class

  • android.view.View
  • Base class for ALL UI elements
  • Every UI element you see on the screen is either a view or a subclass of View.
  • Handles drawing, sizing, and interaction
  • Examples: TextView, Button, ImageView

2.   ViewGroup

  • android.view.ViewGroup
  • Invisible containers for views
  • A subclass of View that can contain other Views (called children).
  • Manage child view positioning/layout
  • Subclasses: LinearLayout, ConstraintLayout

  Layout Managers (ViewGroup Subclasses)

Layout TypeKey FeaturesUse Case
ConstraintLayoutFlexible constraints, flat hierarchyModern complex UIs
LinearLayoutHorizontal/vertical stackingSimple lists/forms
RelativeLayoutPosition relative to siblings/parentDeprecated (use Constraint)
FrameLayoutStacks views (z-index)Fragments/overlays
RecyclerViewDynamic lists with view recyclingScrollable data sets
TableLayoutOrganizes content into rows and columnsForms and structured data display

Best Practice:

✅ Use ConstraintLayout to minimize nesting

✅ Prefer RecyclerView over ListView

🧩 Widgets – Building Blocks of UI

  • Basic interactive elements
  • Declared in XML or Java
  • Common Widgets:
    • TextView – shows text
    • EditText – input field
    • Button – clickable action
    • ImageView – displays image
    • CheckBox, RadioButton, ProgressBar

📌 Used to display or collect information from users.

📦 Containers (ViewGroups) – Organize Widgets

  • Layouts that hold other views/widgets
  • Define how UI elements are arranged
Layout TypeUse Case
LinearLayoutSimple row/column structure
RelativeLayoutPosition based on relations
ConstraintLayoutFlexible & modern layouts
FrameLayoutOverlapping views
ScrollViewScrollable content
RecyclerViewEfficient list display

Android User Interface

Fig: Android User Interface Architecture

Android resources

Resources in Android are external files and data used by your app — like texts, images, colors, and layouts — separated from your code to make it more organized, reusable, and easier to manage.

  Types of Android Resources

1. Layout 

  • Folder: res/layout/
  • Contains XML files for designing the user interface.
  • Example: activity_main.xml, fragment_home.xml

2. Drawable 

  • Folder: res/drawable/
  • Stores images, vector files, and shape drawables.
  • Supports multiple formats: .png, .jpg, .xml

3. Value 

  • Folder: res/values/
  • Holds XML files for:
    • Strings (strings.xml)
    • Colors (colors.xml)
    • Dimensions (dimens.xml)
    • Styles, themes, etc.
  • Makes UI consistent and easy to manage.

4. Menu 

  • Folder: res/menu/
  • Defines app menus in XML format.
  • Example: main_menu.xml

5. Mipmap 

  • Folder: res/mipmap/
  • Stores app launcher icons in various screen densities.
  • Preferred over drawable/ for app icons.
  • Example: ic_launcher.png

6. Raw 

  • Folder: res/menu/
  • Stores raw files like audio, video, or custom data files.
  • Example: intro.mp3, config.json

5. Font 

  • Folder: res/font/
  • Contains custom font files.
  • Example: roboto_regular.ttf

6. Animator/Animation 

  • Folders: res/animator/ and res/anim/
  • animator/: Property animations (XML-based object animation)
  • anim/: Tween animations like fade, rotate, scale
  • Example: fade_in.xml, slide_up.xml

Android Style

  • A style is a set of attributes that define how a UI element looks.
  • Used to apply the same look to multiple views (like buttons, text, etc.).
<!-- res/values/styles.xml -->

<style name="MyTextStyle">

    <item name="android:textColor">#FF5722</item>

    <item name="android:textSize">18sp</item>

</style>

Android Theme

  • A theme is like a global style applied to the entire app or activity.
  • It controls the look of all UI components, like ActionBar, status bar, buttons, text, etc.
  • Think of it as a “style for the whole app”.
<!-- res/values/themes.xml -->

<style name="MyAppTheme" 

parent="Theme.MaterialComponents.DayNight.DarkActionBar">

    <item name="colorPrimary">#6200EE</item>

    <item name="colorPrimaryVariant">#3700B3</item>

    <item name="colorOnPrimary">#FFFFFF</item>

</style>

Add in Android Manifest as

<!-- AndroidManifest.xml -->
<application
    android:theme="@style/MyAppTheme">
</application>

Android 3rd Party UI/UX Libraries

Android 3rd Party UI/UX Libraries are ready-made code packages created by developers or organizations (outside of Google) that help improve the User Interface (UI) and User Experience (UX) of Android apps.

✅ In Simple Terms:

They are pre-built tools that save time by offering:

  • Beautiful designs
  • Smooth animations
  • Useful components (like image loaders, charts, sliders, etc.)

Instead of building everything from scratch, you can plug in these libraries into your project and focus on your app logic.

Why use libraries?

1. Saves Development Time

  • Libraries offer ready-made components like custom buttons, charts, or image loaders.
  • Instead of coding everything from scratch, you can plug and play features.
  • Helps you focus on core features instead of reinventing the wheel.

Example:
Using Glide for image loading is faster than writing your own image caching and decoding logic.


🎨 2. Offers Professional-Level UI/UX

  • Many libraries come with polished and modern designs.
  • They follow best practices and material design guidelines.
  • Improves your app’s look and feel without hiring a designer.

Example:
Lottie allows adding high-quality animations easily.


3. Tested and Used by Thousands

  • Popular libraries are open-source and community-tested.
  • Bugs and issues are usually fixed quickly.
  • Well-documented and maintained by experienced developers.

Example:
Retrofit is widely trusted for network calls — it’s secure, efficient, and tested.


📱 4. Keeps Your App Modern and Engaging

  • Users expect apps to feel smooth, animated, and interactive.
  • UI/UX libraries help your app feel up-to-date with industry standards.
  • Keeps you competitive in the app market.

Example:
Using Material Components gives you the latest design patterns from Google.

Some of libraries

  1. Shimmer (Facebook)
  • Use: Show shimmering placeholders while content loads.
  • implementation ‘com.facebook.shimmer:shimmer:0.5.0’
  1. Glide
  • Use: Efficient image loading and caching.
  1. Lotte
  • Use: Load smooth animations from JSON files (After Effects).

Conclusion

Designing a great Android user interface is not just about looks — it’s about usability, consistency, and adaptability across the vast range of Android devices. By understanding screen sizes, densities, orientation handling, and using units like dp and sp, developers can ensure a responsive and user-friendly experience. Leveraging the right View and ViewGroup classes, along with best practices like using ConstraintLayout, alternative resources, and responsive layouts, helps create scalable and polished UIs that delight users and meet platform standards. A well-crafted UI not only improves usability but also boosts engagement, retention, and app store success.

Let’s get connected

We can be friends. Find on FacebookLinkedinGithubYouTube

BuyMeACoffee, and Instagram.

Contribute: BuyMeACoffee

ContactContact Us