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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:41:36+00:00 2026-05-28T13:41:36+00:00

I got some trouble with the TableLayout Android. I wanna create a table with

  • 0

I got some trouble with the TableLayout Android. I wanna create a table with symmetric rows/columns, i.e. a layout where every TextView in it gets allocated exactly the same amount of space like all the others, no matter what text has been appended to it.

It’s important that this can be done by the use of Java-code, not the XML-files.

It would be probably good to know that this layout requires two tables to be next to each other, i.e. every table has just 50% of the screen size. I suppose this makes several LayoutParameter unavailable (e.g. FILL_PARENT)?

This is what I tried:

for (String s : buffer) {
            TextView tv = new TextView(this);
            tv.setLayoutParams(new TableRow.LayoutParams(0x00, LayoutParams.WRAP_CONTENT, 1f));
            tv.append(s);       
            row.addView(tv, new TableRow.LayoutParams(LayoutParams.FILL_PARENT));   
        }   

Still looks bad though.

  • 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-28T13:41:37+00:00Added an answer on May 28, 2026 at 1:41 pm

    This will create two columns that share’s the width in an orderly fashion.

    <TableLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TableRow>
            <!-- Set the width to 0dp and set layout_weight=1! on both Views-->
            <TextView
                android:text="This is text1, its pretty long but that shouldn't be a problem"
                android:layout_marginLeft="1px"
                android:background="#ff0000"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content" />
    
            <TextView
                android:text="Shorter"
                android:background="#00ff00"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content" />
        </TableRow>
    </TableLayout>
    

    Edit: Same thing, but now in code:

        TableLayout layout = new TableLayout(this);
        TextView t1 = new TextView(this);
        t1.setBackgroundColor(Color.BLUE);
        t1.setText("This is text1, its pretty long but that shouldn't be a problem");
        TextView t2 = new TextView(this);
        t2.setBackgroundColor(Color.GRAY);
        t2.setText("Shorter");
    
        TableRow row = new TableRow(this);
        row.addView(t1, new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f));
        row.addView(t2, new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f));
    
        layout.addView(row);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got some trouble with the media backend (mostly Stagefrightplayer) in Android, and I'd
I've got some trouble with jQuery script on my Asp.net page. During first load
I've got some trouble with displaying pdfs in IE7 (which were generated by R&OS'
I'm having some trouble understanding a bit of code. I've got 2 classes Company
Got some trouble with my preg_match. The code. $text = tel: 012 213 123.
I've got some trouble with the <video> element I guess. I have a little
I'm having some trouble with a fluid layout (with images using max-width:100%) in Internet
I´m having some trouble deciding in which way to go... I've got this application
I'm having some trouble here. I've got a tableview, with 7 cells, all of
I'm having some trouble understanding why this code won't work. I got it from

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.