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 8169049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:43:40+00:00 2026-06-06T20:43:40+00:00

I want this table to extend as possible to fill the remaining (empty) area

  • 0

I want this table to extend as possible to fill the remaining (empty) area of the linear layout that contains it

enter image description here

I generate the table using the following method

public void drawTable(LinearLayout tableLayout,String tableTitle, String[][] data,String[] headerTitles, int type){

        //clearing previous views
         tableLayout.setVisibility(View.VISIBLE);
         tableLayout.setGravity(Gravity.CENTER);
         int chids = tableLayout.getChildCount();
         if (chids > 0){
             tableLayout.removeAllViews();
         }

        if((headerTitles!= null) && (headerTitles.length != data[0].length) ){
            return;
        }

        TableLayout table = new TableLayout(context);  
//      table.setStretchAllColumns(true);  
//      table.setShrinkAllColumns(true);  


        //Rendering the table title
        TextView tableTitleView = new TextView(context);
        tableTitleView.setText(tableTitle);
        tableTitleView.setTextColor(Color.WHITE);
        tableTitleView.setGravity(Gravity.CENTER);
        tableTitleView.setTextSize(18);
        tableTitleView.setTextAppearance(context, R.style.boldText);
        tableTitleView.setBackgroundColor(Color.parseColor("#008888"));
        tableTitleView.setPadding(2, 2, 2, 10);
        tableLayout.addView(tableTitleView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));








        ScrollView scroll1 = new ScrollView(context);
        HorizontalScrollView scroll2 = new HorizontalScrollView(context);


        int rows = data.length;
        int columns = data[0].length;

        if(headerTitles!=null){
            //Rendering the header
            TableRow headerRow = new TableRow(context);
            for (int i = 0; i < columns; i++) {
                TextView t = new TextView(context);
                t.setTextSize(17);
                t.setTextAppearance(context, R.style.boldText);
                t.setPadding(5, 5, 5, 5);
                t.setText(headerTitles[i]);
                t.setGravity(Gravity.CENTER);
                t.setTextColor(Color.WHITE);
                t.setBackgroundResource(R.drawable.text_border_header_1);
                headerRow.addView(t, LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT);
            }
            table.addView(headerRow, new TableLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        }

        //Rendering the Table Data
        TableRow row;
        for (int current = 0; current < rows ; current++) {
            row = new TableRow(context);
            TextView t;
            for(int i =0 ; i < columns ; i++){
                t = new TextView(context);
                t.setTextSize(15);
                t.setPadding(5,5,5,5);
                t.setText(data[current][i]);
                t.setGravity(Gravity.CENTER);

                if (type == 1) {
                    if (current % 2 == 0) {
                        t.setBackgroundResource(R.drawable.text_border_odd);
                    } else {
                        t.setBackgroundResource(R.drawable.text_border_even);
                    }
                }else if (type == 2) {
                    if (current % 2 == 0) {
                        t.setBackgroundResource(R.drawable.text_border_odd_2);
                    } else {
                        t.setBackgroundResource(R.drawable.text_border_even_2);
                    }
                }else if (type == 3) {
                    if (current % 2 == 0) {
                        t.setBackgroundResource(R.drawable.text_border_odd_3);
                    } else {
                        t.setBackgroundResource(R.drawable.text_border_even_3);
                    }
                }

                t.setTextColor(Color.BLACK);
                row.addView(t,TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
            }

            table.addView(row, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

        }
        scroll2.addView(table,LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
        scroll1.addView(scroll2,LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
        scroll1.setPadding(2, 20, 2, 20);

        tableLayout.addView(scroll1,LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);


    }

I couldn’t figure out exactly the problem with my code.

EDIT :

when I added the table directly to the linear layout instead of the scroll views the table fits with the linear layout width. It seems that my problem is with the scroll view

  • 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-06-06T20:43:41+00:00Added an answer on June 6, 2026 at 8:43 pm

    I found the answer Here (thanks to Felix)

    Just a single line of code to be added to the scroll views

    scrollView.setFillViewPort(true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create this table in Oracle. This is only the table SQL
this table i want to create job_id dynamic Jobs Title text Job Description text
I want to create this JSF table with paging and sorting. This is JSF
I want to search the computer from this table and when i have stored
I have this table: User id INT PK login VARCHAR UNIQUE I want to
I have a table and this table contain multiple columns. I want to know
First Table is the View and Second is the result I want This below
I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in
I want to run this on my table: ALTER TABLE table_name MODIFY col_name VARCHAR(255)
I have this JSF table. I want to add row numbers. <?xml version=1.0 encoding=UTF-8?>

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.