Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4271926
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:30:30+00:00 2026-05-21T07:30:30+00:00

I have a TableLayout with just a single row (i.e. the Header Row) in

  • 0

I have a TableLayout with just a single row (i.e. the Header Row) in XML. Other all rows I add dynamically.
XML PART :

    <TableLayout android:id="@+id/list_table" 
    android:layout_width="match_parent" android:layout_height="wrap_content" 
    android:stretchColumns="1" android:background="#808000" **android:scrollbars="vertical">**
    <TableRow android:layout_margin="1dp" android:layout_height="wrap_content" 
    android:layout_width="wrap_content" android:id="@+id/list_head_Row">
        <TextView android:layout_width="wrap_content"  
        android:text="Col1" android:layout_height="wrap_content"></TextView>
        <TextView android:gravity="center" android:layout_width="wrap_content" android:text="Col2" android:layout_height="wrap_content"></TextView>
        <TextView android:layout_width="wrap_content" android:text="Col3"  android:layout_height="wrap_content"></TextView>
    </TableRow>
</TableLayout>

In Activity class, I add TableRows :

TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
// Add 3 TextViews
// Add Row to table
t1.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,             LayoutParams.WRAP_CONTENT));

With this much all rows gets added to the table and fills the screen. I want to set is, view only 4-5 rows and others can be scrolled.For that I added :

    int tableHgt = t1.getChildAt(0).getHeight() + (rowHgt *40);
    t1.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, tableHgt));

With this I can’t see any row at all except the header row added in xml. How can I make its height to see just 5 rows and othe all can be scrolled ? In TableLayout android:scrollbars="vertical" is also added.

Where am I going wrong ?

Any help is highly appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:30:31+00:00Added an answer on May 21, 2026 at 7:30 am

    why don’t you use ListView ?

    but ok … back to your question
    put TableLayout in ScrollView and setup height in ScrollView

    EDIT: code

    activity.java

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scrolltest);
    
        TableLayout t1 = (TableLayout) findViewById(R.id.list_table);
    
        for (int i = 0; i < 10; i++) {
            TableRow tr = new TableRow(this);
            tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                    TableRow.LayoutParams.WRAP_CONTENT));           
            t1.addView(tr, new TableLayout.LayoutParams(
                    TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));  
            TextView tv = new TextView(this);
            tr.addView(tv, new TableRow.LayoutParams(
                    TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
            tv.setText(Integer.toString(i));
            tv = new TextView(this);
            tr.addView(tv, new TableRow.LayoutParams(
                    TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
            tv.setText("Row number");
            tv = new TextView(this);
            tr.addView(tv, new TableRow.LayoutParams(
                    TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
            tv.setText(Integer.toString(i));        
        }
    }
    

    scrolltest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="100dp"
        android:id="@+id/list_scroll">
        <TableLayout android:id="@+id/list_table"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:stretchColumns="1">
            <TableRow android:layout_margin="1dp" android:layout_height="wrap_content"
                android:layout_width="fill_parent" android:id="@+id/list_head_Row"
                android:background="#808000">
                <TextView android:layout_width="wrap_content" android:text="Col1"
                    android:layout_height="wrap_content" />
                <TextView android:gravity="center" android:layout_width="wrap_content"
                    android:text="Col2" android:layout_height="wrap_content" />
                <TextView android:layout_width="wrap_content" android:text="Col3"
                    android:layout_height="wrap_content" />
            </TableRow>
        </TableLayout>
    </ScrollView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TabLayout. In that I have a tablelayout with dynamically added rows.
I have the following problem spanning dynamically added rows to a TableLayout inside a
I have tableLayout filled with a lot of rows (in xml). I wrapped it
I have a TableLayout defined in my xml with three columns and four rows
I have a layout issue. What I do is this: create TableLayout in xml
I need to have an edit option in tableLayout just like in iphone UITableView
I have an xml file right now which has a TableLayout within a LinearLayout.
In the layout below I expect the rows to have exact heights first row
I have a TableLayout in my app, which I need to define and add
I have a simple Table Layout with an empty row <TableRow android:id=@+id/range_input1 > </TableRow>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.