2016-05-21 12 views
0

Ich habe große Schwierigkeiten mit dem Versuch, ein einfaches Layout mit zwei TextView: s unter einander auf der linken Seite und zwei korrespondierenden TimePicker: s unter einander auf der rechten Seite zu erstellen. Aber egal welche Ansicht ich verwende oder welche Attribute ich aussuche, die relevant erscheinen, ich bekomme nicht das gewünschte Ergebnis. Hier ist meine aktuelle Versuch ist:Android: Wie man Layouts versteht?

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:stretchColumns="1" 
    > 
    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center_horizontal" 
     > 
     <TextView 
      android:layout_column="1" 
      android:id="@+id/text_start_time" 
      android:text="@string/start_time" 
      android:gravity="center_horizontal" 
      /> 
     <TimePicker 
      android:id="@+id/time_picker_start" 
      android:timePickerMode="spinner" 
      android:layout_marginTop="-25dp" 
      android:layout_marginBottom="-25dp" 
      android:layout_gravity="center" 
      /> 
    </TableRow> 
    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center_horizontal" 
     > 
     <TextView 
      android:layout_column="1" 
      android:id="@+id/text_end_time" 
      android:text="@string/end_time" 
      android:layout_gravity="center_horizontal" 
      /> 
     <TimePicker 
      android:id="@+id/time_picker_end" 
      android:timePickerMode="spinner" 
      android:layout_marginTop="-25dp" 
      android:layout_marginBottom="-25dp" 
      /> 
    </TableRow> 
    <TableRow> 
     <Button 
      android:layout_column="2" 
      android:layout_width="match_parent" 
      android:text="@string/button_calculate" 
      android:gravity="center" 
      android:onClick="calculateWorkingTime" 
      /> 
    </TableRow> 
</TableLayout> 

Dies ergibt die folgende Ausgabe

Where is "Start"?

Wie Sie sehen können "Start" ist nicht einmal gezeigt! Ich möchte "Start" mit der vertikalen Mitte des TimePicker Spinner ausrichten. Wie geht das?

Antwort

0

Verwenden Sie zunächst kein TableLayout. Verwenden Sie Linears, da Sie Anfänger sind und sie einfacher zu verwenden und zu verstehen sind. Hier ist, was Sie tun sollten:

<?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" > 

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

     <TextView 
      android:id="@+id/text_start_time" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/start_time" 
      android:gravity="center_horizontal" 
      /> 

     <TimePicker 
      android:id="@+id/time_picker_start" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:timePickerMode="spinner" 
      android:layout_marginTop="-25dp" 
      android:layout_marginBottom="-25dp" 
      android:layout_gravity="center" 
      /> 
    </LinearLayout> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

     <TextView 
      android:id="@+id/text_end_time" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/end_time" 
      android:gravity="center_horizontal" 
      /> 

     <TimePicker 
      android:id="@+id/time_picker_end" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:timePickerMode="spinner" 
      android:layout_marginTop="-25dp" 
      android:layout_marginBottom="-25dp" 
      android:layout_gravity="center" 
      /> 
    </LinearLayout> 
    <Button 
      android:layout_column="2" 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:text="@string/button_calculate" 
      android:gravity="center" 
      android:onClick="calculateWorkingTime" 
      /> 
    </LinearLayout> 

Was ich getan habe, ist die Schaffung eines Linear-Layout und in sie, zwei weitere mit Orientierung: horizontal, die die Elemente erscheinen nebeneinander macht. Auch habe ich Breite und Höhe zu allen Elementen, was sehr wichtig ist. Ich habe wrap_content, wenn Sie es ändern wollen, kein Problem.

ich es nicht testen, haben, wenn ein Fehler es gibt, coment nur

Hoffe, es hilft!

Verwandte Themen