The RelativeLayout subclass provides a container that allows us to position views, and even other layouts, based on each others' screen locations. Like the LinearLayout that we saw in the previous section, the RelativeLayout is also a ViewGroup; but it is particularly useful for reducing the number of other ViewGroups that we may have otherwise nested within it, which in turn saves vital memory.
We are going to set up a single RelativeLayout
that contains widgets which are aligned both horizontally and vertically.
Start up a new Android project in Eclipse.
Open the
res/layout/main.xml
file with the Graphical Layout tab and delete the default TextView by selecting it and pressing Delete.Open
main.xml
with the main.xml tab so that you can edit the code directly, delete the lineandroid:orientation="vertical"
, and change the opening and closing tag types fromLinearLayout
toRelativeLayout
. Themain.xml
file should then look like this:<...