xml relative Layout und weights Problem

  • Antworten:3
Steffen H.
  • Forum-Beiträge: 6

13.07.2011, 22:41:36 via Website

Hallo Leute,
Ich habe den Bildschirm grob in 2 Hälften unterteilt. Die linke Hälfte ist dabei ca. 20% groß und die rechte 80%. Mit Linearlayouts alles soweit gut, doch jetzt habe ich in die linke Hälfte ein relative layout mit darin ausgerichteten TextViews verbaut. Die linke Hälfte ist jetzt viel zu groß und sollte eigentlich nur in etwa so groß sein wie der Text Platz beansprucht.

Hier mal ein Bild.

und hier meine xml:
1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout
3 xmlns:android="http://schemas.android.com/apk/res/android"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent">
6 <LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1" android:layout_height="fill_parent" android:baselineAligned="false" android:orientation="horizontal" android:padding="0dp">
7 <LinearLayout android:id="@+id/relativeLayout1" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:background="#ccc" android:orientation="vertical">
8 <RelativeLayout android:id="@+id/Rl1" android:gravity="bottom" android:layout_height="match_parent" android:layout_width="match_parent" android:layout_weight="1">
9 <TextView android:text="Text" android:id="@+id/Stunde1" android:layout_alignParentLeft="true" android:textColor="#000000" android:layout_width="wrap_content" android:gravity="center" android:layout_height="fill_parent" android:layout_marginRight="10dp"></TextView>
10 <TextView android:text="Text" android:id="@+id/textView5" android:textColor="#000000" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/Stunde1" android:layout_width="wrap_content"></TextView>
11 <TextView android:layout_width="wrap_content" android:text="Text" android:id="@+id/textView6" android:textColor="#000000" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_height="wrap_content" android:layout_toRightOf="@+id/Stunde1"></TextView>
12 </RelativeLayout>
13 </LinearLayout>
14 <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:id="@+id/relativeLayout1" android:layout_height="match_parent" android:layout_weight="1" android:layout_margin="0dp" android:background="#eee">
15 <TextView android:text="Linear Layout 1" android:id="@+id/textView3" android:textColor="#000000" android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_weight="1" android:gravity="center" android:background="#bbb"></TextView>
16 </LinearLayout>
17 </LinearLayout>
18</LinearLayout>

Habe ich hier irgendein wichitges Atribut vergessen oder die TextViews falsch ausgerichtet? Ich habe schon alle möglichen Kombination der weight werte ausprobiert, doch ich brauch schon unmenschlich große zahlen um die beiden Hälften nur annähernd gleich groß zu bekommen, geschweigen denn die linke kleiner ;) Hoffe ihr könnt mir helfen.

mfg Steffen

Antworten
Marcel B.
  • Forum-Beiträge: 31

14.07.2011, 09:15:46 via Website

Heiho,

soweit ich das beim Überfliegen gesehen habe, hat jede deiner Seiten ein weight="1" und dein RelativeLayout das NUR so groß sein soll wie die Textbox hat match_parent.

Mach mal bei der rechten (LinearLayout) fill_parent und lass weight="1" (heißt er nimmt allen übrigen Platz ein) und beim anderen (RelativeLayout) machst du das weight weg und machst wrap_content (soll ja nur so groß sein wie der Inhalt)

Gruß Marcel

P.S wenns genau 20 / 80 sein soll musst du anders vorgehen
P.S.S http://developer.android.com/guide/topics/ui/index.html das ist hilfreich

— geändert am 14.07.2011, 09:18:36

Antworten
Steffen H.
  • Forum-Beiträge: 6

14.07.2011, 16:32:07 via Website

Danke für deine Antwort, ich habe tatsächlich bei der rechten Spalte kein fill_parent gemacht sondern versehentlich ein wrap_content. Dummer Fehler, kommt wohl davon wenn man zu oft immer Grafikeditor dinge verschiebt :D. Jetzt klappt alles, wundert mich nur dass ich den Fehler nicht selbst gefunden habe da ich alles ca eine halbe stunde vergeblich durchsucht habe. Das offensichtliche hab ich übersehen ;D

mfg Steffen

Antworten
Marcel B.
  • Forum-Beiträge: 31

14.07.2011, 16:50:47 via Website

Das passiert mir auch immer ^^

Antworten