TableLayout

  • Antworten:6
Tanja Z.
  • Forum-Beiträge: 52

30.12.2010, 18:42:28 via Website

Hallo!

Ich möchte ein Table-Layout machen, in dem zwei gleichgroße EditText-Boxen nebeneinander erscheinen sollen, habe alles mögliche probiert, der Emulator zeigt die erste Box immer kleiner an als die zweite. Kann mir jemand sagen, woran das liegt bzw. wie ich das ändern kann? So sieht der Code momentan aus:


<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
android:id="@+id/tv_rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tx01"
android:textStyle="bold"/>

<TableRow
>

<TextView
android:id="@+id/tv_datum"
android:text="@string/tx_datum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/tv_uhr"
android:text="@string/tx_uhrzeit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableRow>

<TableRow
>
<EditText
android:id="@+id/edt_datum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<EditText
android:id="@+id/edt_uhrzeit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableRow>

Antworten
Gelöschter Account
  • Forum-Beiträge: 294

30.12.2010, 19:44:44 via Website

Versuch mal bei allen EditText zusätzlich "android:layout_weight="1" anzugeben. Optional noch alle layout_height="wrap_content" und alle layout_width="fill_parent".

Ich habe schon ungezählte Stunden an diesen Layout Parametern verpulvert.

Gruß
Harald

Antworten
Tanja Z.
  • Forum-Beiträge: 52

30.12.2010, 20:27:36 via Website

Hallo Harald!

Vielen Dank für Deine schnelle Antwort! Leider funktioniert dies auch nicht. Evtl. noch eine andere Idee?


Gruß, Tanja

Antworten
Gelöschter Account
  • Forum-Beiträge: 294

31.12.2010, 07:16:54 via Website

Ich sehe gerade das Du eine TextView ohne TableRow da drin hast. Das ist mir gestern abend nicht aufgefallen. Mach da eine TableRow drum. Verpass diesem TextView einen Layout_Span="2" und gib allen TextViews ebenfalls einen Layout_weight="1" - ausser dem einzelnen TextView der müsste eine 2 bekommen.

Gruss
Harald

Antworten
Tanja Z.
  • Forum-Beiträge: 52

31.12.2010, 13:13:15 via Website

Es tut sich leider gar nichts.


Gruß, Tanja

Antworten
Gelöschter Account
  • Forum-Beiträge: 294

31.12.2010, 14:34:08 via Website

Ich mache das eigentlich immer so - klappt auch bisher - mehr oder weniger ;-)

Ein eigenes Beispiel das mir beim Coden gerade über den Weg lief:
1<?xml version="1.0" encoding="utf-8"?>
2
3<ScrollView
4 xmlns:android="http://schemas.android.com/apk/res/android"
5 android:layout_height="wrap_content"
6 android:layout_width="fill_parent" >
7
8 <TableLayout
9 android:id="@+id/tablelayout"
10 android:layout_height="wrap_content"
11 android:layout_width="fill_parent"
12 android:paddingRight="2dip"
13 android:stretchColumns="*" >
14
15 <TableRow
16 android:layout_height="wrap_content"
17 android:layout_width="fill_parent"
18 android:orientation="horizontal"
19 android:paddingBottom="2dip"
20 android:paddingTop="2dip" >
21
22 <TextView
23 style="@style/ActivityTitleBar"
24 android:layout_span="2"
25 android:layout_weight="2"
26 android:text="Bla" />
27 </TableRow>
28
29 <TableRow
30 android:layout_height="wrap_content"
31 android:layout_width="fill_parent"
32 android:orientation="horizontal"
33 android:paddingBottom="2dip"
34 android:paddingTop="2dip" >
35
36 <TextView
37 style="@style/TextViewStandard"
38 android:layout_weight="1"
39 android:text="Bla" />
40
41 <EditText
42 style="@style/EditTextStandard"
43 android:id="@+id/bla"
44 android:layout_weight="1" />
45 </TableRow>
46
47 <TableRow
48 android:layout_height="wrap_content"
49 android:layout_width="fill_parent"
50 android:orientation="horizontal"
51 android:paddingBottom="2dip"
52 android:paddingTop="2dip" >
53
54 <TextView
55 style="@style/TextViewStandard"
56 android:layout_weight="1"
57 android:text="Bla2" />
58
59 <EditText
60 style="@style/EditTextStandard"
61 android:id="@+id/bla2"
62 android:layout_weight="1" />
63 </TableRow>
64
65 <TableRow
66 android:layout_height="wrap_content"
67 android:layout_width="fill_parent"
68 android:orientation="horizontal"
69 android:paddingBottom="2dip"
70 android:paddingTop="2dip" >
71
72 <Button
73 style="@style/ButtonStandard"
74 android:layout_marginTop="6dip"
75 android:layout_weight="1"
76 android:layout_width="0dip"
77 android:onClick="onClickOk"
78 android:text="@android:string/ok" />
79 </TableRow>
80 </TableLayout>
81</ScrollView>

Und hier die relevanten Einträge aus der zugehörigen styles.xml:
1<?xml version="1.0" encoding="utf-8"?>
2
3<resources>
4 <style name="ActivityTitleBar">
5 <item name="android:background">@drawable/titlebar</item>
6 <item name="android:gravity">center</item>
7 <item name="android:layout_height">wrap_content</item>
8 <item name="android:layout_width">fill_parent</item>
9 <item name="android:singleLine">true</item>
10 <item name="android:textColor">#fff</item>
11 <item name="android:textSize">14sp</item>
12 <item name="android:textStyle">bold</item>
13 </style>
14
15 <style name="ButtonStandard" parent="@android:style/Widget.Button">
16 <item name="android:layout_height">wrap_content</item>
17 <item name="android:layout_width">fill_parent</item>
18 </style>
19
20 <style name="EditTextStandard" parent="@android:style/Widget.EditText">
21 <item name="android:layout_height">wrap_content</item>
22 <item name="android:layout_marginLeft">2dip</item>
23 <item name="android:layout_marginRight">2dip</item>
24 <item name="android:layout_marginTop">2dip</item>
25 <item name="android:layout_width">fill_parent</item>
26 </style>
27
28 <style name="TextViewStandard" parent="@android:style/Widget.TextView">
29 <item name="android:layout_height">wrap_content</item>
30 <item name="android:layout_marginLeft">2dip</item>
31 <item name="android:layout_marginRight">2dip</item>
32 <item name="android:layout_marginTop">2dip</item>
33 <item name="android:layout_width">fill_parent</item>
34 <item name="android:textColor">@android:color/white</item>
35 </style>
36</resources>

Tanja Z.

Antworten
Tanja Z.
  • Forum-Beiträge: 52

03.01.2011, 20:38:04 via Website

Ich wünsche Euch ein gutes neues Jahr!

@Harald

Vielen Dank für Deine Hilfe. Ich hab das Layout etwas umgebaut (TextView und EditText nebeneinander) , so wie aus Deinem Beispiel. Sieht auch ganz gut aus, zwei gleichgroße EditText - Boxen gehen irgendwie nicht.


Gruß, Tanja

Antworten