Now that you know how to create layouts in XML and Java, and how to set their height and width, you can take a closer look at two of the most commonly used layouts: the straightforward and easy-to-use LinearLayout
layout and the incredibly flexible RelativeLayout
layout.
LinearLayout
aligns all its children in a single horizontal or vertical row, stacking them one after the other.
You set the direction of your LinearLayout
layout using either of the following:
android:orientation="horizontal."
: The views are placed next to each other in rows. A horizontalLinearLayout
layout is only ever one row high.android:orientation="vertical."
: The views are placed below each other in columns. A verticalLinearLayout
layout only ever has one child per row.
Here's a simple LinearLayout
layout with a horizontal orientation:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation...