Ich habe Probleme damit Layouts gut aussehen.Mit einem Taschenrechner mit einem GridLayout vergelten
Um die Grundlagen zu verstehen, habe ich beschlossen, eine einfache Taschenrechner-App zu erstellen.
Also verwende ich ein GridLayout in einem LinearLayout geschachtelt, um Schaltflächen unter Textfelder zu platzieren.
Hier ist die Quelle meines Layouts.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100">
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="0"
android:layout_weight="30"/>
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:columnCount="4"
android:rowCount="5"
android:orientation="horizontal"
android:useDefaultMargins="false"
android:layout_weight="70">
<Button
android:text="C" />
<Button
android:text="BS" />
<Button
android:text="/" />
<Button
android:text="x" />
<Button
android:text="7" />
<Button
android:text="8" />
<Button
android:text="9" />
<Button
android:text="-" />
<Button
android:text="4" />
<Button
android:text="5" />
<Button
android:text="6" />
<Button
android:text="+" />
<Button
android:text="1" />
<Button
android:text="2" />
<Button
android:text="3" />
<Button
android:layout_gravity="fill"
android:layout_rowSpan="2"
android:text="=" />
<Button
android:layout_gravity="fill"
android:layout_columnSpan="2"
android:text="0" />
<Button
android:text="." />
</GridLayout>
</LinearLayout>
Wie kann dieses Layout den Bildschirm füllen?
Und meine App wie diese
der Hoffnung auf schnelle Antworten suchen machen.
[EDIT]: So, jetzt sind die Dinge viel besser, aber ich habe neue Fragen. Jetzt sieht meine Haupttätigkeit wie dieses
Ganz nett, meiner Meinung nach, aber:
- Wie leeren Raum auf der rechten Seite der Tastatur entfernen?
- Wie machen Tastatur und Text-Ansicht nehmen wie 70 und 30 Prozent des Bildschirms jeweils?
Auch neue Layout-Code ist:
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="android.calcandroid.MainActivity">
<TextView
android:background="@drawable/shape"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:text="0"
android:layout_above="@+id/gridLayout" />
<GridLayout
android:id="@+id/gridLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:columnCount="4"
android:rowCount="5"
android:orientation="horizontal"
android:useDefaultMargins="false">
<Button
android:background="@drawable/shape"
android:text="C" />
<Button
android:background="@drawable/shape"
android:text="BS" />
<Button
android:background="@drawable/shape"
android:text="/" />
<Button
android:background="@drawable/shape"
android:text="x" />
<Button
android:background="@drawable/shape"
android:text="7" />
<Button
android:background="@drawable/shape"
android:text="8" />
<Button
android:background="@drawable/shape"
android:text="9" />
<Button
android:background="@drawable/shape"
android:text="-" />
<Button
android:background="@drawable/shape"
android:text="4" />
<Button
android:background="@drawable/shape"
android:text="5" />
<Button
android:background="@drawable/shape"
android:text="6" />
<Button
android:background="@drawable/shape"
android:text="+" />
<Button
android:background="@drawable/shape"
android:text="1" />
<Button
android:background="@drawable/shape"
android:text="2" />
<Button
android:background="@drawable/shape"
android:text="3" />
<Button
android:background="@drawable/shape"
android:layout_gravity="fill_vertical"
android:layout_rowSpan="2"
android:text="=" />
<Button
android:background="@drawable/shape"
android:layout_gravity="fill_horizontal"
android:layout_columnSpan="2"
android:text="0" />
<Button
android:background="@drawable/shape"
android:text="." />
</GridLayout>
</RelativeLayout>
Versuchen Sie es mit einem TableLayout. Dann können Sie die Spalten strecken, um die Breite des Bildschirms anzupassen –
Und Gitter könnte es nicht tun? – likeanowl
Ein GridView oder GridLayout wäre einfach perfekt für eine Taschenrechner App. –