O'Reilly logo

Android Design Patterns and Best Practice by Kyle Mew

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Relative layouts

Probably the biggest advantage of the relative layout is the way it can be used to reduce the number of nested view groups when building complex layouts. This works by defining views' positions in accordance to how they are positioned and aligned to each other with properties such as layout_below and layout_toEndOf. To see how this is done, consider the linear layout of the previous example. We can recreate this as a relative layout with no nested viewgroups, like so:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/header" android:layout_width="match_parent" android:layout_height="56dp" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required