2016-11-19 54 views
0

我在父LinearLayout中使用TableLayout,並且我在TableLayout中有幾個EditText視圖。我完全茫然,爲什麼所看到下面的圖片中的EditText意見超過我的佈局的屏幕尺寸:破碎的Android佈局

enter image description here

這裏是我的XML代碼:

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

任何幫助將不勝感激。先謝謝你。

回答

0

因爲你沒有設置寬度和這些元素的重量。嘗試將寬度設置爲wrap_content並使用weight值進行操作,直到獲得所需的值。此外,請檢查this question以瞭解有關LinearLayout和重量的更多說明。

編輯

TextViews和EditText上的ems屬性將影響佈局爲好。如果您希望它們的比例相同,請在兩者中使用相同的比例。

+0

這是'ems'屬性搞亂了佈局。謝謝! – KJG