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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:58:17+00:00 2026-06-14T13:58:17+00:00

For example I create 4 tablerows programatically and I want each tablerow height to

  • 0

For example I create 4 tablerows programatically and I want each tablerow height to be 1/4 size of the screen. Each tablerow height is half the screen size. I tried different ways, but tablerow height didn’t change. I manage change tablerow width, but height doesn’t.
Here is my code :

@SuppressLint("NewApi")
public class GameActivity extends Activity {

    private Context context;

    public void drawTable(){
        int i;
        TableLayout table = new TableLayout(context);

        table.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
        //table.setStretchAllColumns(true);
        //table.setShrinkAllColumns(true);
        //table.setWeightSum(1.0F);
        TableRow[] rows = new TableRow[5];
        for(i = 0; i < 4; ++i){
            rows[i] = new TableRow(context);
            rows[i].setBackgroundResource(R.drawable.images214);
            rows[i].setWeightSum((float)1.0);
            rows[i].setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, 10));
            //rows[i].setScaleY(0.25F);
            table.addView(rows[i]);
        }

        LinearLayout l = (LinearLayout) findViewById(R.id.linear);
        l.addView(table);
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game);

        context = this;
//        TableLayout table = new TableLayout(this);
//        TableRow row1 = new TableRow(this);
//        TableRow row2 = new TableRow(this);
//        row1.addView(new EditText(this));
//        row2.addView(new Button(this));
//        table.addView(row1);
//        table.addView(row2);
//        //table.setBackground(getResources().getDrawable(R.drawable.ic_launcher));
//        table.setBackgroundResource(R.drawable.ic_launcher);
//        LinearLayout l = (LinearLayout) findViewById(R.id.linear);
//        l.addView(table);
        drawTable();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_game, menu);
        return true;
    }
}

XML:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

  <ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="none"
    android:layout_weight="1">
        <LinearLayout 
         android:id="@+id/linear" 
         android:layout_width="match_parent"
         android:layout_height="match_parent"  
         android:scrollbars="vertical|horizontal">
        </LinearLayout>
 </ScrollView>
</RelativeLayout>
  • 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-14T13:58:18+00:00Added an answer on June 14, 2026 at 1:58 pm

    You’re not using the proper LayoutParams, for the table TableLayoutyou should set LinearLayout.LayoutParams(as you add the table to a LinearLayout) and for your TableRows the LayoutParams should be TableLayout.LayoutParams(as they are children of TableLayout). Even with the above changes things will not work because the TableLayout is a widget that imposes constraints on its children, most notable the height will be automatically set to WRAP_CONTENT for TableRows. The only way to change this is to use weight like this:

    TableLayout table = new TableLayout(context);
    table.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    table.setWeightSum(1.0f);
    TableRow[] rows = new TableRow[4];
    for(int i = 0; i < 4; ++i){
        rows[i] = new TableRow(context);
        rows[i].setBackgroundResource(R.drawable.images214);
        rows[i].setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, 0, 0.25f));        
        table.addView(rows[i]);
    }
    
    LinearLayout l = (LinearLayout) findViewById(R.id.linear);
    l.addView(table);
    

    But this will not work, because your TableLayout is set to fill the parent, parent which is a ScrollView which doesn’t imposes dimensions on its child. I don’t know what you’re trying to do with that ScrollView there(especially as you want the table to fill the entire screen) so I don’t know what to recommend you. Also, I don’t know your full layout but your nesting to many layouts.

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

Sidebar

Related Questions

I want to create an example like the image below but instead have a
In this example I create three buttons 'one' 'two' 'three'. When clicked I want
I want to create an example SaaS app, whereby users are able to signup,
I'm facing an issue on my android application. I want to dynamically create TableRow
I am trying to make a webpage with Ajax. Example: I create a Perl/CGU
I create one example in Android 3.0 and I use the fragment in it.
How is it possible to create for example an object with perspective. For example:
I found an example here to create a select list with optgroups using KnockoutJS.
In the following example i can create an object dynamically via a string; however,
In the following example http://jsfiddle.net/xBRPg/ I'm trying to create a yellow background for one

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.