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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:47:21+00:00 2026-05-23T18:47:21+00:00

This question is actually related to this post Set the layout weight of a

  • 0

This question is actually related to this post Set the layout weight of a TextView programmatically

Based on the answers I just need to set the TextView layout params as follow and set the stretchColumn Property, but by adding the following code to mine, it makes the textView disappear from the Table Layout.

TextView tv = new TextView(v.getContext());
tv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));

So, here is my code where I want to dynamically add a row with 3 columns with 35%, 5% and 60% weight. Please let me know what is wrong with my code.

private void addTableRow(int resIdTitle, String strValue){

        TableRow tr = new TableRow(this);

        // Add First Column
        TextView tvTitle = new TextView(this);
        tvTitle.setText(resIdTitle);
        tvTitle.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT, 0.35f));
        tr.addView(tvTitle);

        // Add 2nd Column
        TextView tvColon = new TextView(this);
        tvColon.setText(" : ");
        tvColon.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT, 0.05f));
        tr.addView(tvColon);

        // Add the 3rd Column
        TextView tvValue = new TextView(this);
        tvValue.setText(strValue);
        tvValue.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT, 0.60f));
        tr.addView(tvValue);

        // Finally add it to the table
        tl.addView(tr, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        Log.d(TAG, "Row Added");
    }

And here is my xml file,

<?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="wrap_content"
        android:layout_weight="1">
    <TableLayout
      android:id="@+id/tl_cam_get_param"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:title="@string/strGetParamTitle" 
      android:scrollbars="vertical"       
      android:shrinkColumns="0">
        </TableLayout>
</ScrollView>

I have also tried setting the layout_width to 0, but still it didn’t work.

Thanks,
artsylar

  • 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-23T18:47:21+00:00Added an answer on May 23, 2026 at 6:47 pm

    Thank you everyone!
    Finally, I was able to solve my problem by referencing to the following posts.

    android: two issues using Tablerow+TextView in Tablelayout

    How to make a TableLayout from XML using programmable way ?

    Refer below for my working code.

    This is where the dynamic adding of rows is done.

    TableLayout tl = (TableLayout)findViewById(R.id.table_layout);
    
    private void addTableRow(int resIdTitle, String strValue){
    
        LayoutInflater inflater = getLayoutInflater();
        TableRow tr = (TableRow)inflater.inflate(R.layout.table_row, tl, false);
    
        // Add First Column
        TextView tvTitle = (TextView)tr.findViewById(R.id.tvTitle);
        tvTitle.setText(resIdTitle);
    
        // Add the 3rd Column
        TextView tvValue = (TextView)tr.findViewById(R.id.tvValue);
        tvValue.setText(strValue);
    
        tl.addView(tr);
    }
    

    This is the table_layout.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="wrap_content"
        android:layout_weight="1">
        <TableLayout
          android:id="@+id/table_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:title="@string/strGetParamTitle" 
          android:scrollbars="vertical"       
          android:shrinkColumns="0">
        </TableLayout>
    </ScrollView>
    

    And finally the table_row.xml. I’ve set all the layout_params here.

    <?xml version="1.0" encoding="utf-8"?>
    <TableRow xmlns:android="http://schemas.android.com/apk/res/android">
       <TextView  
              android:id="@+id/tvTitle"
              android:paddingRight="3dip"
              android:layout_width="0px"
              android:layout_weight="0.35"/>
       <TextView  android:text=":"
              android:layout_width="0px"
              android:layout_weight="0.05"/>
       <TextView
                android:id="@+id/tvValue"
                android:paddingLeft="3dip"
                android:layout_width="0px"
                android:layout_weight="0.6"
              /> 
    </TableRow>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is actually related to another question I had that was already answered. That
The first part of this question is actually a request for confirmation based on
This question is more about guidance than actually solving my problem: I need to
This question is related to this post : int to binary python I have
This is actually related to a question I asked earlier, but I was left
Problem This question actually came up at work today. We are planning an experiment
The Question actually says it all. The reason behind this question is I am
Note: all the quotation marks in this question are actually part of the code.
So, this is actually this question is my current keystone. I'm working on refactoring
I am finally asking this question as I have never actually found an answer.

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.