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:
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?
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>
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>
Do the change as :
<TableLayout
android:id="@+id/follow_up_table"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:stretchColumns="0">
</TableLayout>
Change is :
android:layout_width="**fill_parent**"
What is the purpose of using HorizontalScrollView? Just remove it and set TableLayout's android:layout_width to match_parent.
The layout was required to be edited like this :
<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" >
<TableLayout
android:id="@+id/follow_up_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:stretchColumns="0,1">
</TableLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
The output :
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.