Relative layout is a view group that displays child views in a relative positions. The position of each view can be specified relative to its siblings.
The reference documentation on this can be found at at link below http://developer.android.com/guide/topics/ui/layout/relative.html
There are many layout parameters available and they are mentioned in http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html
Below is a sample which shows this.
the tv_sample is made to the right of the tv_helloworld
Note that we cannot specify a circular dependancy. for e.g. we cannot specify android:layout_toLeftOf="@+id/tv_sample" />, as that will become circular dependancy.
With the below XML, the screenshot from device was like this below
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
android:layout_height="wrap_content"
android:id="@+id/tv_username"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et_username"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:hint="Enter Username"/>
android:layout_height="wrap_content"
android:id="@+id/tv_password"
android:layout_below="@+id/tv_username"
android:paddingTop="25dp"
android:layout_alignParentLeft="true" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et_password"
android:layout_alignParentRight="true"
android:hint="Enter Password"
android:layout_below="@+id/et_username"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/button"
android:layout_below="@+id/et_password"
android:layout_alignParentRight="true"/>
Screenshots:

It is difficult to make any kind of complicated ui with relative layout as many developers say.
I was trying to specify the layout widths with this layout, however, was unable to achieve so far.
References:
No comments:
Post a Comment