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

The Archive Base Latest Questions

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

I have a simple problem for Android. I’d like to create an n by

  • 0

I have a simple problem for Android. I’d like to create an n by n table filled with buttons. First I want to calculate the minimum of the screen’s width and height (just because I want to show my table entirely on the screen). I have the following code:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();
int min = Math.min(width, height);
int buttonSize = (int)Math.floor(min / dimension);

TableLayout rootLayout = (TableLayout)this.findViewById(R.id.tableLayout1);

for (int i = 0; i < dimension; ++i)
{
  LinearLayout lLayout = new LinearLayout(this);
  lLayout.setOrientation(0);
  rootLayout.addView(lLayout);

  for (int j = 0; j < dimension; ++j)
  {
    Button b = new Button(this);
    b.setText("-");
    b.setPadding(0, 0, 0, 0);
    b.setWidth(buttonSize);
    b.setHeight(buttonSize);

    lLayout.addView(b);
  }
}

I can’t figure out why the buttons’ width and height don’t get set. I tried to populate the table from the designer by specifying the width and height and then it worked.

Any help is really appreciated.

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

    I would set the LinearLayout.LayoutParams of each button as well? Give it a shot…

    b.setLayoutParams(
        new LinearLayout.LayoutParams(width, height)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to make a simple layout in android but have problem with the
i have very simple problem. I need to create model, that represent element of
I have a problem using opengl on android to draw a simple rectangle. This
This may seem like a simple problem to solve, but I'm new to Android
I'm writing a simple xmpp client in android and I have a problem with
I have a simple activity in android where I'm doing something like: givepassw =
I have a simple problem when querying the SQL Server 2005 database. I have
I have a simple problem that i cannot solve. I have a dictionary: aa
I have a simple problem but I am not sure how to solve it.
I have a simple problem but no matter what I try I can't see

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.