Reputation: 27
I am having trouble getting a table row implemented. My coding is not allowing me add custom widths to my editText controls. Can someone please point out what the problem might be for table tableRow2? I want the feet and inches editText to be beside each other with a width of 40dp. Thanks in advance!
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal">
<TableRow android:layout_height="wrap_content" android:id="@+id/tableRow1"
android:padding="5dp" android:layout_width="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/grainBinType"
android:textSize="14sp" />
<Spinner android:id="@+id/spinner1" android:layout_height="wrap_content"
android:layout_width="200dp" android:paddingLeft="8dp"
android:entries="@array/grainBinTypes" android:prompt="@string/rfDefault" />
</TableRow>
<TableRow android:layout_height="wrap_content" android:id="@+id/tableRow2"
android:padding="5dp" android:layout_width="wrap_content">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/radiusOfBin"
android:textSize="14sp" android:paddingRight="8dp" />
<EditText android:id="@+id/editTextFeet"
android:layout_width="40dp" android:layout_height="wrap_content"
android:inputType="number" android:textColor="#008000" android:ems="10"
android:paddingRight="8dp" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/feet"
android:textSize="14sp" android:paddingRight="8dp" />
<EditText android:id="@+id/editTextinches"
android:layout_width="40dp" android:layout_height="wrap_content"
android:inputType="number" android:textColor="#008000" android:ems="10" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/inches"
android:textSize="14sp" />
</TableRow>
Upvotes: 0
Views: 592
Reputation: 34765
Firstly if we use tablelayout then we usually use table row and in each table row all the elements must be equal. I means in your first table you have two elements and in second you have five. that is the problem. in the first table row change the width of spinner 40dp will also effect it to Edittext.... I suggest you to use LinearLayout for your requirement...
Use below code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout android:layout_height="wrap_content" android:id="@+id/tableRow1"
android:padding="5dp" android:layout_width="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/grainBinType"
android:textSize="14sp" />
<Spinner android:id="@+id/spinner1" android:layout_height="wrap_content"
android:layout_width="200dp" android:paddingLeft="8dp"
android:entries="@array/grainBinTypes" android:prompt="@string/rfDefault" />
</LinearLayout>
<LinearLayout
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="8dp"
android:text="@string/radiusOfBin"
android:textSize="14sp" />
<EditText
android:id="@+id/editTextFeet"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:paddingRight="8dp"
android:textColor="#008000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="8dp"
android:text="@string/feet"
android:textSize="14sp" />
<EditText
android:id="@+id/editTextinches"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:textColor="#008000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/inches"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
Upvotes: 1