Button doppelt so groß darstellen

D

Duckemai

Fortgeschrittenes Mitglied
6
Hallo zusammen,

ich habe eine Frage zu den Layout-Tags.

Ich habe mir eigene Buttons definiert. 4 in jeder Reihe, in 5 Zeilen.
So weit, so gut.
In der letzten Zeile will ich aber nur 3 Buttons haben und der erste soll
doppelt so lang sein, also den Raum von 2 Buttons einnehmen.
Easy, dachte ich, und habe folgendes gemacht:

<LinearLayout
android: orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">

Und habe dann für den ersten folgenden Button das layout_weight auf "2" gesetzt, die anderen beiden auf "1".

Klappt aber nicht. Dem Button fehlt ein Stück, um bis zur Hälfte
des Bildschirms zu kommen. Dementsprechend sind die beiden anderen
etwas zu groß.

Ein Denkfehler?

Danke im Voraus.
Duckemai
 
Zuletzt bearbeitet:
denkfehler == true | android:layout_weight="1" == füllen JA | android:layout_weight="0" == füllen NEIN
 
Das man grundsätzlich android:layout_weight einsetzen kann war ja nun klar. Aber ich versuche damit eine bestimme Aufteilung der Buttons zu erreichen.

Jemand eine Idee, ob ich dafür layout_weight benutzen kann oder etwas anderes?
 
Common Layout Objects | Android Developers
layout_weight ist ansich genau richtig.
Ist wohl nur etwas zickig ;)

Tip: To create a proportionate size layout on the screen, create a container view group object with the layout_width and layout_height attributes set to fill_parent; assign the children height or width to 0 (zero); then assign relative weight values to each child, depending on what proportion of the screen each should have.

Kannst du mal die komplette xml posten?

Edit: Ich bekomm es auch nicht besser hin, bei mir verschwinden die Buttons, die ich auf 2 setze :D
 
Zuletzt bearbeitet:
Gerne. Hier die dazugehörige main.xml:

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

//erste Reihe mit 4 Buttons
<LinearLayout
android: orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">

<Button ...android:layout_weight="1" ...</Button>
<Button ...android:layout_weight="1" ...</Button>
<Button ...android:layout_weight="1" ...</Button>
<Button ...android:layout_weight="1" ...</Button>

//ab hier die 2. Reihe mit nur 3 Buttons. Der erste soll so lang sein wie die ersten 2 Buttons darüber

<LinearLayout
android: orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">

<Button
android:text="@string/numinfo"
android:id="@+id/Button17"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="2" />

<Button
android:text="@string/numpunkt"
android:id="@+id/Button19"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1" />

<Button
android:text="@string/numgleich"
android:id="@+id/Button20"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1" />

</LinearLayout>
</LinearLayout>
 
android:layout_width="wrap_content"
probier da mal bei den drei Buttons fill_parent. sonst fällt mir nix ein.
Oder aber nach dem Zitat oben layout_width="0" setzen.
 
Zuletzt bearbeitet:
Doppelpost, Die Lösung wollte ich einzeln haben:
layout_width="0dip"

Mein Beispiel sind 3 Reihen mit 4 Buttons und eine Reihe mit 3, wovon einer doppelt so dick ist wie die anderen.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:text="01" android:id="@+id/Button01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
<Button android:text="05" android:id="@+id/Button05" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
<Button android:text="06" android:id="@+id/Button06" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
<Button android:text="07" android:id="@+id/Button07" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:text="02" android:id="@+id/Button02" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
<Button android:text="08" android:id="@+id/Button08" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
<Button android:text="09" android:id="@+id/Button09" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
<Button android:text="10" android:id="@+id/Button10" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:text="03" android:id="@+id/Button03" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
<Button android:text="11" android:id="@+id/Button11" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
<Button android:text="12" android:id="@+id/Button12" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
<Button android:text="13" android:id="@+id/Button13" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"></Button>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<Button android:text="04" android:id="@+id/Button04" android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="2"></Button>
<Button android:text="14" android:id="@+id/Button14" android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1"></Button>
<Button android:text="15" android:id="@+id/Button15" android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1"></Button>
</LinearLayout>
</LinearLayout>
 
  • Danke
Reaktionen: Duckemai
Danke schön,
genau das war es!

android:layout_width="0dip" und nicht fill_parent.

Daumen rauf,
Duckemai
 

Ähnliche Themen

A
  • AnimaAngelo85
Antworten
1
Aufrufe
313
swa00
swa00
MES
Antworten
10
Aufrufe
788
MES
MES
C
Antworten
8
Aufrufe
1.111
swa00
swa00
Zurück
Oben Unten