In RelativeLayout all views are positioned relatively to each other. This means that you can create an EditText element and then create a button and say that you want this button to be positioned to left of the EditText. View can be positioned relatively to its sibling elements or to its parent layout.
Many say that RelativeLayout is the hardest to master, but I honesty don't think so at all. RelativeLayout is very flexible and I am sure that if you spend some time just playing around with it, you'll find it very easy to use as well ;)
RelativeLayout Example
Here is a RelativeLayout example, that will help you understand the idea of it better:
acitivity_main.xml file:
DEMO
Android RelativeLayout |
Explanation:
Button 1 position: android:layout_alignParentBottom="true"
If true, this attribute makes the bottom edge of the element match the bottom edge of the parent.
Button 2 position: android:layout_toRightOf="@id/editext1"
Positions the left edge of this view to the right of the given anchor view ID (in our case to the right of edittext1 element).
Button 3 position:
1. android:layout_alignParentEnd="true"
If true, makes the end edge of this view match the end edge of the parent.
2. android:layout_alignParentBottom="true"
If true, this attribute makes the bottom edge of the element match the bottom edge of the parent.
Here we are using two attributes to first position our button on the bottom of the parent view and then move it to the end of it.
ImageView position: android:layout_centerInParent="true"
If true, centers this child horizontally and vertically within its parent.
Full list of all possible attributes can be found right here:
http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html