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

  • SEARCH
  • Home
  • 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 8842459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:57:50+00:00 2026-06-14T10:57:50+00:00

I have a problem when I set the TableRow layout_weight programmatically. Following code is

  • 0

I have a problem when I set the TableRow layout_weight programmatically.
Following code is the TableLayout inflated in table_body element:

<TableLayout
     android:layout_width="match_parent"
     android:layout_height="0px"
     android:layout_weight="1"
     android:weightSum="1">
<TableLayout>

I want to display only 10 rows in TableLayout.. and to do this i add TableRow elements programmatically using this is the code:

while(i<10){
    TableRow row = (TableRow) ((Activity) context).getLayoutInflater().
        inflate(R.layout.body_row, table_body, false);

    TableRow.LayoutParams row_params = 
        new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 0, 0.1f);

    table_body.addView(row, row_params);

    i++;
}

body_row.xml has this code:

<TableRow>
    <TextView 
        android:text="row1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</TableRow>

With this code TableLayout is not divided in 10 equal space (as I’d want) but rows only wrap their content with the result of blank space between the end of last row and the end of the TableLayout.. What I’m doing wrong?
Thank you!!

  • 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-14T10:57:51+00:00Added an answer on June 14, 2026 at 10:57 am

    To make the weight mechanism work you need to use the proper LayoutParams for your inflated TableRow widgets. As the parent of TableRow is a TableLayout then you need to use the TableLayout.LayoutParams:

    TableLayout.LayoutParams row_params = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 0.1f);
    table_body.addView(row, row_params);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following structure in my UI <ScrollView android:id=@+id/vscroll android:layout_width=match_parent android:layout_height=match_parent> <TableLayout android:id=@+id/table
I have a problem with this is code: Set oXmlHTTP = CreateObject(Microsoft.XMLHTTP) oXmlHTTP.Open POST,
i have problem to set tabindex to FCK editor . i am using following
i have problem with autorotate on iphone i set up in all classes -
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
Hi all I have problem with my div's in html. I have set them
Hi I have problem with html height. My height is now set to pixels
The problem: I have set of pictures, when the user presses on one of
I have a problem with a javascript set of functions that I made. This
I have a problem removing breakpoints that are set when I attach to a

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.