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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:19:01+00:00 2026-05-27T13:19:01+00:00

I’m facing an issue on my android application. I want to dynamically create TableRow

  • 0

I’m facing an issue on my android application. I want to dynamically create TableRow in a TableLayout. Each of this row needs to contain 4 TextViews.
I want the TextView like this:

  • textview1: 40% of the screen
  • textview2: 10% of the screen
  • textview3: 10% of the screen
  • textview5: 40% of the screen

I manage to create the Tewtview dynamically but the size are not respected. For example if my first textview contains a big text, it covers all the screen instead of only 40% and multiline.

I read a lot of similar questions but can’t find the solution here. Here is my layout file:

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginBottom="30dip"
android:id="@+id/journee_contenu">

<TableRow>
  <!-- Column 1 -->
  <TextView
     android:id="@+id/tbl_txt1"
     android:layout_width="0dip"
     android:layout_height="wrap_content"
     android:layout_weight="4"
     android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
      />

  <!-- Column 2 -->
  <TextView
     android:id="@+id/tbl_txt2"
     android:layout_width="0dip"
     android:layout_height="wrap_content"
     android:layout_weight="1"
     android:text="bbbbb"
     />

  <!-- Column 3 -->
  <TextView
     android:id="@+id/tbl_txt3"
     android:layout_width="0dip"
     android:layout_height="wrap_content"
     android:layout_weight="1"
     android:text="ccccc"
      />
      <!-- Column 4 -->
  <TextView
     android:id="@+id/tbl_txt4"
     android:layout_width="0dip"
     android:layout_height="wrap_content"
     android:layout_weight="4"
     android:text="ddddddddddddddddddddddddddddddddddddddddddddddd"
      />
</TableRow>

The Layout creates a static tab with a first row that is as I want it to be. But the rows added dynamically are not behaving the same way.

My dynamic code:

    TableLayout genLayout = (TableLayout) findViewById(R.id.journee_contenu);
for (MatchWrapper match : matchs) {
    TableRow tr1 = new TableRow(this);
    TextView tvEq1 = new TextView(this);
    tvEq1.setText(match.getEquipe1());
    TextView tvSc1 = new TextView(this);
    tvSc1.setText(match.getScore_equipe1());
    TextView tvSc2 = new TextView(this);
    tvSc2.setText(match.getScore_equipe2());
    TextView tvEq2 = new TextView(this);
    tvEq2.setText(match.getEquipe2());
    tr1.addView(tvEq1);
    tr1.addView(tvSc1);
    tr1.addView(tvSc2);
    tr1.addView(tvEq2);
    genLayout.addView(tr1);
}

My match object is only containing string with various size. Thanks a lot for your help

  • 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-27T13:19:02+00:00Added an answer on May 27, 2026 at 1:19 pm

    The reason your dynamicly added TableRows don’t do as you would like is that you do not set the LayoutParams for the TableRow nor the TextViews.

    On each TextView you add LayoutParams like this:

    tvEq1.setLayoutParams( new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 4 ) );
    tvSc1.setLayoutParams( new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1 ) );
    tvSc2.setLayoutParams( new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1 ) );
    tvEq2.setLayoutParams( new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 4 ) );
    

    The last parameter of the LayoutParams-constructor is the layout_weight.

    You need to add the LayoutParams before addind the TextViews to the TableRow.

    You might need to add LayoutParams to your TableRow aswell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.