Wednesday 17 August 2016

Relative Layout



Relative Layout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent Relative Layout area (such as aligned to the bottom, left or center).






Note : By default, all child views are drawn at the top-left of the layout, so you must define the position of each view using the various layout properties available from RelativeLayout.LayoutParams.
Some of the many layout properties available to views in a RelativeLayout include:
If "true", makes the top edge of this view match the top edge of the parent.
2.    android:layout_centerVertical : If "true", centers this child vertically within its parent.
3.    android:layout_below : Positions the top edge of this view below the view specified with a resource ID.
4.    android:layout_toRightOf : Positions the left edge of this view to the right of the view specified with a resource ID.
code –


<?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"
    android:paddingLeft="16dp"
    android:paddingRight="16dp" >
    <EditText
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="editext" />
    <TextView
        android:id="@+id/dates"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="textview"
        android:background="#FF6267"
        android:layout_below="@id/name"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/times" />
    <TextView
        android:id="@id/times"
        android:layout_width="96dp"
        android:layout_height="wrap_content"
        android:text="textview-2"
        android:background="#48C9B1"
        android:layout_below="@id/name"
        android:layout_alignParentRight="true" />
    <Button
        android:layout_width="96dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/times"
        android:layout_alignParentRight="true"
        android:text="done" />
</RelativeLayout>


XML Attributes
Attribute Name and Description                                                                                                
1.    android:layout_above  - Positions the bottom edge of this view above
 The  given anchor view ID.                                                                                                          
2.    android:layout_alignBaseline - Positions the baseline of this view on the
baseline of the given anchor view ID.                                                                                                    
3.    android:layout_alignBottom - Makes the bottom edge of this view match the
bottom edge of the given anchor view ID.                                                                                                          
4.    android:layout_alignEnd -           Makes the end edge of this view match the end
edge of the given anchor view ID.                                                                                                           
5.    android:layout_alignLeft -           Makes the left edge of this view match the left
edge of the given anchor view ID.                                                                                                           
6.    android:layout_alignParentBottom - If true, makes the bottom edge of this view match  the bottom edge of the parent.                                                                                                            
7.    android:layout_alignParentEnd -          If true, makes the end edge of this view match
the end edge of the parent.                                                                                                           
8.    android:layout_alignParentLeft -           If true, makes the left edge of this view match the left edge of the parent.                                                                                                 
9.    android:layout_alignParentRight - If true, makes the right edge of this view match
the right edge of the parent.                                                                                                          
10. android:layout_alignParentStart -         If true, makes the start edge of this view
Match  the start edge of the parent.                                                                                             
11. android:layout_alignParentTop - If true, makes the top edge of this view
Match  the top edge of the parent.                                                                                               
12. android:layout_alignRight - Makes the right edge of this view match the
Right  edge of the given anchor view ID.                                                                                   
13. android:layout_alignStart -          Makes the start edge of this view match the
Start edge of the given anchor view ID.                                                                                      
14. android:layout_alignTop - Makes the top edge of this view match the top
edge of the given anchor view ID.                                                                                               
15. android:layout_alignWithParentIfMissing - If set to true, the parent will be used as the anchor when the anchor cannot be be found for  layout_toLeftOf, layout_toRightOf, etc.                                                                                                            
16. android:layout_below - Positions the top edge of this view below the given anchor view ID.                                                                                                   
17. android:layout_centerHorizontal - If true, centers this child horizontally within its
 parent.                                                                                                          
18. android:layout_centerInParent - If true, centers this child horizontally and
vertically within its parent.                                                                                                 
19. android:layout_centerVertical : If true, centers this child vertically within its
parent.                                                                                                           
20. android:layout_toEndOf : Positions the start edge of this view to the end of
 the given anchor view ID.                                                                                                            
21. android:layout_toLeftOf : Positions the right edge of this view to the left of
 the given anchor view ID.                                                                                                
22. android:layout_toRightOf :          Positions the left edge of this view to the right of  the given anchor view ID.                                                                                           
23. android:layout_toStartOf : Positions the end edge of this view to the start of
the given anchor view ID.                                                                                                 



No comments:

Post a Comment