SamplesRelativLayout
1. Samples
The first sample show a TextView and a EditText.
The EditText must lay below the TextView.
Complete Project
RelativeLayout1.7z
Beispielcode
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Matrikelnummer" /> <EditText android:id="@+id/edittext2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:lines="1" android:text="In diesem Textfield kann man bestimmt etwas eingeben" android:layout_below="@id/textview1" /> </RelativeLayout>
2. Samples
The second sample show a TextView, a TextView and a Button.
The EditText must lay below the TextView.
The Button must lay below the EditText.
Complete Project
RelativeLayout2.7z
sample code
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Matrikelnummer" /> <EditText android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:lines="1" android:text="In diesem Textfield kann man bestimmt etwas eingeben" android:layout_below="@id/textview1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Klick mich" android:layout_below="@id/edittext1" /> </RelativeLayout>
3. Samples
The second sample show a TextView, a TextView and a Button.
The EditText must lay below the TextView.
The Button must lay below the EditText.
Now the Button have a right position.
Complete Project
RelativeLayout3.7z
sample code
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Matrikelnummer" /> <EditText android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:lines="1" android:text="In diesem Textfield kann man bestimmt etwas eingeben" android:layout_below="@id/textview1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Klick mich" android:layout_below="@id/edittext1" android:layout_alignParentRight="true" /> </RelativeLayout>
4. Samples
The second sample show a TextView, a TextView and a two Buttons.
The EditText must lay below the TextView.
The Buttons "ok" and "Cancel" must lay below the EditText.
The Button "ok" must have a left position in the view.
The Button "Cancel" must have a right position in the view.
Complete Project
RelativeLayout4.7z
sample code
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Matrikelnummer" /> <EditText android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:lines="1" android:text="In diesem Textfield kann man bestimmt etwas eingeben" android:layout_below="@id/textview1" /> <Button android:id="@+id/bnOk" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:layout_below="@id/edittext1" android:layout_alignParentLeft="true" /> <Button android:id="@+id/bnCancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Abbrechen" android:layout_below="@id/edittext1" android:layout_alignParentRight="true" /> </RelativeLayout>
5. Samples
The second sample show a TextView, a TextView and a two Buttons.
The EditText must lay below the TextView.
The Buttons "ok" and "Cancel" must lay below the EditText.
In this sample the two buttons must lay on the right position in the view.
Complete Project
RelativeLayout5.7z
sample code
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Matrikelnummer" /> <EditText android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:lines="1" android:text="In diesem Textfield kann man bestimmt etwas eingeben" android:layout_below="@id/textview1" /> <Button android:id="@+id/bnCancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Abbrechen" android:layout_below="@id/edittext1" android:layout_alignParentRight="true" /> <Button android:id="@+id/bnOk" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:layout_below="@id/edittext1" android:layout_toLeftOf="@id/bnCancel" /> </RelativeLayout>
6. Samples
The second sample show a TextView, a TextView and a two Buttons.
The EditText must lay below the TextView.
The Buttons "ok" and "Cancel" must lay below the EditText.
In this sample the two buttons must lay on the left position in the view.
Complete Project
RelativeLayout5.7z
sample code
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Matrikelnummer" /> <EditText android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:lines="1" android:text="In diesem Textfield kann man bestimmt etwas eingeben" android:layout_below="@id/textview1" /> <Button android:id="@+id/bnOk" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ok" android:layout_below="@id/edittext1" android:layout_alignParentLeft="true" /> <Button android:id="@+id/bnCancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Abbrechen" android:layout_below="@id/edittext1" android:layout_toRightOf="@id/bnOk" /> </RelativeLayout>