0

I am using a TableLayout within a parent LinearLayout and I have a few EditText views in the TableLayout. I am at a complete loss as to why the EditText views exceed the screen dimensions of my layout as seen in the following image:

enter image description here

Here is my 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>

Any help would be appreciated. Thank you in advance.

Chisko
  • 3,092
  • 6
  • 27
  • 45
KJG
  • 5
  • 1

1 Answers1

0

Because you are not setting the width nor the weight of those elements. Try setting width to wrap_content and play with the weight values until you get what you want. Also, check this question for further clarificarion about LinearLayout and weight.

EDIT:

The ems property of TextViews and EditText will impact the layout as well. If you want them in the same proportions, use the same in both.

Community
  • 1
  • 1
Chisko
  • 3,092
  • 6
  • 27
  • 45