2016-11-19 2 views
0

Ich verwende ein TableLayout in einem übergeordneten LinearLayout und ich habe ein paar EditText-Ansichten in der TableLayout. Ich bin zu einem vollständigen Verlust, warum die EditText Ansichten, die die Bildschirmabmessungen meines Layout überschreiten, wie im folgenden Bild zu sehen:Gebrochenes Android-Layout

enter image description here

Hier ist meine XML-Code:

<?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:id="@+id/activity_view_edit_location_parameters" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.kg.hvacloadestimator.ViewEditLocationParameters"> 

     <TextView 
      android:text="@string/Location" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/location" /> 

     <TextView 
      android:text="@string/Summer_Outside_db" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/summerDB" /> 

     <TextView 
      android:text="@string/Winter_Outside_db" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/winterDB" /> 

     <TextView 
      android:text="@string/Daily_Range" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/dailyRange" /> 

     <CheckBox 
      android:text="@string/Checkbox_Custom_Conditions" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:onClick="onCheckboxClicked" 
      android:id="@+id/checkBoxCustomConditions" /> 

     <TableLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

       <TableRow 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 

         <TextView 
          android:text="@string/Custom_Location" 
          android:layout_height="wrap_content" 
          android:id="@+id/textViewCustomLocation" /> 

         <EditText 

          android:layout_height="wrap_content" 
          android:inputType="textPersonName" 
          android:text="@string/Default_Custom_Location" 
          android:ems="10" 
          android:id="@+id/editTextCustomLocation" /> 
       </TableRow> 

       <TableRow 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 

         <TextView 
          android:text="@string/Custom_Summer_db" 
          android:layout_height="wrap_content" 
          android:id="@+id/textViewCustomSummerDB" /> 

         <EditText 

          android:layout_height="wrap_content" 
          android:inputType="numberSigned|numberDecimal" 
          android:ems="10" 
          android:id="@+id/editTextCustomSummerDB" 
          android:text="@string/Default_Custom_Summer_db" /> 
       </TableRow> 

       <TableRow 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 

         <TextView 
          android:text="@string/Custom_Winter_db" 
          android:layout_height="wrap_content" 
          android:id="@+id/textViewCustomWinterDB" /> 

         <EditText 

          android:layout_height="wrap_content" 
          android:inputType="numberSigned|numberDecimal" 
          android:ems="10" 
          android:id="@+id/editTextCustomWinterDB" 
          android:text="@string/Default_Custom_Winter_db" /> 
       </TableRow> 

       <TableRow 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 

         <TextView 
          android:text="@string/Custom_Daily_Range" 
          android:layout_height="wrap_content" 
          android:id="@+id/textView4" /> 

         <Spinner 
          android:layout_height="wrap_content" 
          android:id="@+id/spinnerCustomDailyRange" /> 
       </TableRow> 
     </TableLayout> 

     <Button 
      android:text="@string/Button_Confirm_Location" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:onClick="onButtonClick" 
      android:id="@+id/buttonConfirmLocation" /> 

</LinearLayout> 

Jede Hilfe würde geschätzt werden. Vielen Dank im Voraus.

Antwort

0

Weil Sie weder die Breite noch das Gewicht dieser Elemente festlegen. Versuchen Sie, die Breite auf wrap_content einzustellen und spielen Sie mit den weight Werten, bis Sie das bekommen, was Sie wollen. Überprüfen Sie auch this question für weitere Klarstellung über LinearLayout und Gewicht.

EDIT:

Die ems Eigenschaft von Textviews und EditText wird auch das Layout auswirken. Wenn Sie sie in den gleichen Proportionen möchten, verwenden Sie das gleiche in beiden.

+0

Es war die 'ems' Eigenschaft, die das Layout durcheinander brachte. Vielen Dank! – KJG

Verwandte Themen