Expand button in TableRow

178 Views Asked by At

I have at the bottom of the screen 2 buttons for next and previous inside table rows in a table layout as below.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000" >

        <TableLayout
            android:id="@+id/table1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:background="#000000"
            >

            <TableRow
                android:background="#000000"
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:textColor="#FFFFFF"
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                     />

                <TextView />

            </TableRow>

            <TableRow
                android:background="#000000"
                android:id="@+id/tableRow2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:textColor="#FFFFFF"
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                     />

            </TableRow>

            <TableRow
                android:background="#000000"
                android:id="@+id/tableRow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:gravity="center"
                >

                <ImageView
                    android:id="@+id/imageView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:scaleType="fitCenter"
                    android:adjustViewBounds="true"
                    android:visibility="gone"
                    />

                <ProgressBar
                    android:id="@+id/progressBar1"
                    style="?android:attr/progressBarStyleLarge"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:visibility="visible" 
                    />

            </TableRow>

            <TableRow
                android:background="#000000"
                android:id="@+id/tableRow4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
                <TextView
                    android:textColor="#FFFFFF"
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                     />
            </TableRow>

            <TableRow
                android:background="#000000"
                android:id="@+id/tableRow5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="fill" 
                >


                 <Button
                    android:id="@+id/next"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:onClick="goNext"
                    android:text="Next" />
            </TableRow>

             <TableRow
                android:background="#000000"
                android:id="@+id/tableRow6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <Button
                    android:id="@+id/previous"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:onClick="goPrevious"
                    android:text="Previous" />

            </TableRow>
        </TableLayout>
    </ScrollView>

</LinearLayout>

However, The buttones next and previous don't fill the row. I want to expand both buttons to fill the row (parent)? Any suggestions?

enter image description here

2

There are 2 best solutions below

0
On BEST ANSWER

Use Layout_weight for Buttons

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000" >

        <TableLayout
            android:id="@+id/table1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:background="#000000"
            >

            <TableRow
                android:background="#000000"
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:textColor="#FFFFFF"
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                     />

                <TextView />

            </TableRow>

            <TableRow
                android:background="#000000"
                android:id="@+id/tableRow2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:textColor="#FFFFFF"
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                     />

            </TableRow>

            <TableRow
                android:background="#000000"
                android:id="@+id/tableRow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:gravity="center"
                >

                <ImageView
                    android:id="@+id/imageView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:scaleType="fitCenter"
                    android:adjustViewBounds="true"
                    android:visibility="gone"
                    />

                <ProgressBar
                    android:id="@+id/progressBar1"
                    style="?android:attr/progressBarStyleLarge"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:visibility="visible" 
                    />

            </TableRow>

            <TableRow
                android:background="#000000"
                android:id="@+id/tableRow4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
                <TextView
                    android:textColor="#FFFFFF"
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                     />
            </TableRow>

            <TableRow
                android:background="#000000"
                android:id="@+id/tableRow5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="fill" 
                >


                 <Button
                    android:id="@+id/next"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:onClick="goNext"
                    android:layout_weight="1"
                    android:text="Next" />
            </TableRow>

             <TableRow
                android:background="#000000"
                android:id="@+id/tableRow6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <Button
                    android:id="@+id/previous"
                    style="?android:attr/buttonStyleSmall"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:onClick="goPrevious"
                      android:layout_weight="1"
                    android:text="Previous" />

            </TableRow>
        </TableLayout>
    </ScrollView>

</LinearLayout>

I changed it copy and Paste It will work Thanks

0
On

Change TableRow layout_width="match_parent" around buttons