Android RelativeLayout

January 11, 2018 Oclemy Android Layout 0 minutes, 54 seconds

Android RelativeLayout

RelativeLayout is a viewgroup that arranges it's views relative to each other.


In RelativeLayout you can define the positions of child views in relation to the each other or to the parent.

Relative layout resides in the android.widget package:

package android.widget;

It's actually a ViewGroup in that it derives from android.view.ViewGroup class:

 public class RelativeLayout extends ViewGroup{}

Advantages of RelativeLayout

RelativeLayout has the following main advantages:

  1. It's very flexible and easy to use and can be produce many layout designs as compared to the others.
  2. RelativeLayout can eliminate the need to nest different layouts just to achiece a given design.
  3. RelativeLayout's flat hierarchy therefore leads to improved performance that would otherwise be negatively affected with nested layouts.

RelativeLayout Children

RelativeLayout has 3 direct subclasses:

No. SubClass Description
1. SearchBar SearchBar is a search widget that contains a search orb and a text entry view.
2. PercentRelatieLayout This class extends from RelativeLayout and also allows you use percentage-based dimensions and margins.
3. DialFilter RelativeLayout child that provides several methods and constants to filter digits, letters etc in the dialing app.