Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table layout not fitting screen

I have an activity which creates a table dynamically. The activity is created and is working fine.

This is the source code of the xml file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#142c57"
    tools:context=".TableActivity" >

    <TextView
        android:id="@+id/heading_textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:text="@string/followup_list" 
        android:textColor="#FFFFFF"
        android:textSize="15sp"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/heading_textView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp" 
        android:padding="3dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true" 
            android:background="@drawable/inner_box">

            <ScrollView
                android:id="@+id/scrollView1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true" >

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

                    <HorizontalScrollView
                        android:id="@+id/horizontalScrollView1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true" >

                        <TableLayout
                            android:id="@+id/follow_up_table"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent" 
                            android:stretchColumns="0">


                        </TableLayout>

                    </HorizontalScrollView>

                </RelativeLayout>

            </ScrollView>

        </RelativeLayout>

    </RelativeLayout>

</RelativeLayout>

The output of the xml file:

output

I want the table to fill the whole box, the space on the right hand side of the table is not required and is looking awkward. What is to be done to achieve this?

like image 460
kittu88 Avatar asked Apr 27 '26 02:04

kittu88


2 Answers

Better yet stretch and shrink all columns to fit your screen with:

<TableLayout
 android:id="@+id/follow_up_table"
 android:layout_width="match_parent"
 android:layout_height="match_parent" 
 android:stretchColumns="*"
 android:shrinkColumns="*">

</TableLayout>
like image 190
Jordan Hochstetler Avatar answered Apr 28 '26 18:04

Jordan Hochstetler


Your table layout width wraps its content, it should be match_parent

<TableLayout
 android:id="@+id/follow_up_table"
 android:layout_width="match_parent"
 android:layout_height="match_parent" 
 android:stretchColumns="0">


</TableLayout>
like image 22
bugraoral Avatar answered Apr 28 '26 18:04

bugraoral



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!