RelativeLayout-Detail

XML-Code für das RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" >

 <TextView
 android:id="@+id/label"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="Enter user name and password:" />

 <EditText
 android:id="@+id/username"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_below="@id/label"/>
 
 <EditText
 android:id="@+id/password"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_below="@id/username" />

 <Button
 android:id="@+id/ok"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@id/password"
 android:layout_alignParentLeft="true"
 android:text="OK" />
 
 <Button
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@id/password"
 android:layout_centerHorizontal="true"
 android:text="Reset" />

 <Button
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@id/password"
 android:layout_alignParentRight="true"
 android:text="Cancel" />

</RelativeLayout>

Erklärung der verschiedenen Komponenten:


android:layout_width Die Breite der Komponente.
android:layout_height Die Höhe der Komponente.
android:layout_weight Das Gewicht der Komponente.
android:background Die Angabe des Hintergrundbildes, bzw. -farbe
android:text Der Text, den das Textfeld enthält
android:textColor Die Textfarbe des Textfeldes.
android:layout_below

Positioniert den oberen Teil der Komponente unterhalb der angegeben ID.

android:layout_alignParentLeft Positioniert den linken Teil der Komponenten an die linke Seite der übergeordneten Komponente.
android:layout_alignParentRight Positioniert den rechten Teil der Komponenten an die rechte Seite der übergeordneten Komponente.
android:layout_centerHorizontal Zentriert die Komponente horizontal.

"android:layout_below="@id/password"" gibt in unserem Fall an, dass sich der Button "OK" unterhalb des "Password"-Eingabefeldes befinden soll.

"android:layout_alignParentLeft" richtet den "OK" Button in unserem RelativeLayout links aus.

"android:layout_alignParentRight" richtet den "Cancel" Button in unserem RelativeLayout rechts aus.

"android:layout_centerHorizontal" zentriert den "Reset" Button.

 

In der Main-Klasse sollte folgendes stehen:

import android.app.Activity;
import android.os.Bundle;

public class Main extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 }
}

Kommentare
Suche
Nur registrierte Benutzer können Kommentare schreiben!

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

The secret of any online business is web hosting. Select the best hosting service reading offered by justhost.
Free Joomla Templates designed by Joomla Hosting