Fertigstellung des Gameoverlayouts
Als Grundlage für dieses Android Tutorial benötigt ihr folgenden Code in eurer gameoverscreen.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="225dp"
android:gravity="center"
android:text="Game Over"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</LinearLayout>
Um die “Properties” Eigenschaften eines Elementes eures Layouts anzeigen zu lassen, müsst ihr einen Rechtsklick auf das Element machen dann auf Show In – Properties. Das kann hilfreich sein um schnell viele Änderungen vorzunehmen und auch gleich zu sehen wie sich die Änderungen auf das Layout auswirken.
“layout_weight”, also das Gewicht des Layouts, verwenden wir hier um den Platz den ein Element einnimmt im Verhältniss zu den anderen Elementen im gleichen LinerarLayout zu setzen.
Wenn also in einem horizontalem Linearlayout ein Button A das Gewicht von 1 und ein anderer Button B das Gewicht von 2 hat, dann ist der Button B doppelt so Breit wie Button A:
[---A---][------B------]
40dp steht für 40 density pixels. Das sind die Pixel deren Größe Abhängig von der Dichte der Pixel auf dem Bildschirm ist.
Wir fügen einige Elemente ein und Am Ende sollte der Code unserer gameoverscreen.xml so aussehen:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Game Over"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_weight="0.5"
android:textSize="40dp"/>
<TextView
android:id="@+id/tvScore"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your Score is: "
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:layout_weight="1"
android:textSize="35dp"/>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/bReplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Replay" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="or"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/bExit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Exit" />
</LinearLayout>
</LinearLayout>