RELATIVELAYOUT 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 RelativeLayout area (such as aligned to the bottom, left, or center).
If you would like to Enrich your career with an Android certified professional, then visit Mindmajix - A Global online training platform:“Android training” Course. This course will help you to achieve excellence in this domain.
These properties will layout elements relative to the parent container.
Here is a sample XML Layout
android:layout_width="fill_parent"android:layout_height="fill_parent"xmlns:android="https://schemas.android.com/apk/res/android">
android:id="@+id/backbutton"
android:text="Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:id="@+id/firstName"
android:text="First Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/backbutton" />
EditText
android:id="@+id/editFirstName"
android:width="100px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/firstName"
android:layout_below="@id/backbutton"/>
android:id="@+id/editLastName"
android:width="100px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editFirstName"
android:layout_alignLeft="@id/editFirstName"/>
android:id="@+id/lastName" android:text="Last
Name" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/editLastName"
android:layout_below="@id/editFirstName" />
You probably noticed that we had to rearrange the elements in the XML since you cannot reference an element that has not already been laid out. Here is what the updated RelativeLayout produces.
TableLayout is a ViewGroup that displays child View elements in rows and columns.TableLayout organizes content into rows and columns. The rows are defined in the layout XML, and the columns are determined automatically by Android. This is done by creating at least one column for each element. So, for example, if you had a row with two elements and a row with five elements then you would have a layout with two rows and five columns.
Here is some sample XML using TableLayout.
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="https://schemas.android.com/apk/res/android">
android:id="@+id/backbutton" android:text="Back" android:layout_width="wrap_content" android:layout_height="wrap_content" />
Checkout Android Interview Questions
android:text="First Name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_column="1" />
android:width="100px"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:text="Last Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
android:width="100px"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
This is the result of that XML
Explore Android Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download Now
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
Android Training | Dec 24 to Jan 08 | View Details |
Android Training | Dec 28 to Jan 12 | View Details |
Android Training | Dec 31 to Jan 15 | View Details |
Android Training | Jan 04 to Jan 19 | View Details |
Ravindra Savaram is a Technical Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.