A K
A K

Reputation: 737

text view bounding box overly sized in table row

This is a scroll view that contains a table layout. When I place a text view inside a table row, by default the bounding box of the text view consumes all available width. As a result when I try placing other views inside the same table row, they are placed outside the layout. In the images below, the first row contains 2 textviews and 2 edittexts but as you can see, 3 of those views are placed outside due to the 1st text view. Any help?

enter image description here

<ScrollView xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView1"
    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=".MainActivity" >

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

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/activity_horizontal_margin">

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/current_bill_text_view" />

            <EditText
                android:id="@+id/CurrentBillEditText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="4"
                android:inputType="numberDecimal" >

                <requestFocus />
            </EditText>

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/tip_text_view" />

            <EditText
                android:id="@+id/TipEditText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="4" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/activity_horizontal_margin"
            android:padding="@dimen/table_row_padding" >

            <SeekBar
                android:id="@+id/TipSeekBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/total_bill_text_view" />

            <EditText
                android:id="@+id/TotalBillEditText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ems="4" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="@dimen/table_row_padding" >

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/introduction_text_view"
                android:textSize="@dimen/activity_horizontal_margin" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/activity_horizontal_margin"
            android:padding="@dimen/table_row_padding" >

            <CheckBox
                android:id="@+id/checkBox1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/friendly" />

            <CheckBox
                android:id="@+id/checkBox2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:text="@string/opinion" />

            <CheckBox
                android:id="@+id/checkBox3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/specials" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="@dimen/table_row_padding" >

            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/availability_text_view"
                android:textSize="@dimen/activity_horizontal_margin" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/activity_horizontal_margin"
            android:padding="@dimen/table_row_padding" >

            <RadioGroup
                android:id="@+id/radioGroup1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <RadioButton
                    android:id="@+id/radio0"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="true"
                    android:text="@string/good" />

                <RadioButton
                    android:id="@+id/radio1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/ok" />

                <RadioButton
                    android:id="@+id/radio2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/bad" />
            </RadioGroup>

        </TableRow>

        <TableRow
            android:id="@+id/tableRow7"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="@dimen/table_row_padding" >

            <Spinner
                android:id="@+id/spinner1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:entries="@array/problem_solving" />

        </TableRow>
    </TableLayout>

</ScrollView>

Upvotes: 0

Views: 879

Answers (1)

KBusc
KBusc

Reputation: 663

Try setting the Weight for each item, something like this

<Button
          android:id="@+id/PunchIn"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_weight="0.50"
          android:text="Punch In" />

<Button
          android:id="@+id/PunchOut"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_weight="0.50"
          android:text="Punch Out" />

This is for two items but for three you could use

android:layout_weight="0.33"

and so on...

Upvotes: 1

Related Questions