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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:27:10+00:00 2026-05-28T07:27:10+00:00

Basically I’m trying to make an application for tablets. There going to be a

  • 0

Basically I’m trying to make an application for tablets.
There going to be a bunch of widgets added and removed by the user inside a table layout. It needs to be dynamic so that the widgets are sized differently based on the width and height of the table layout.

To do this, I’m trying to make a 3×3 grid in a tablelayout. As I’m sure you guessed, each square has 33% width and height of the tablelayout.

This is what I got:

DisplayMetrics metrics;
int totalScreenSizeH; 
int totalScreenSizeW;

TableLayout contentTable;
LinearLayout contentLayout;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //Get the UI detail
    metrics  = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    totalScreenSizeH = metrics.heightPixels;
    totalScreenSizeW = metrics.widthPixels;



    contentTable=(TableLayout)findViewById(R.id.tableLayout1);
    contentLayout=(LinearLayout)findViewById(R.id.contentLayout);

    int tableWidth =contentTable.getWidth();
    int tableHeight=contentTable.getHeight();

    int layoutWidth=contentLayout.getWidth();
    int layoutHeight=contentLayout.getHeight();

    Log.v("Table Width",""+tableWidth);
    Log.v("Table Height",""+tableHeight);

    Log.v("Layout Width",""+layoutWidth);
    Log.v("Layout Height",""+layoutHeight);

So just to explain this a bit better. The linearLayout contains the tablelayout which has 3 table rows. I figured that I would be able to get the width and height of these but for some reason, both are coming back as 0 in size. One I have the width and height dims, Im going to save that variable and the create the widgets based on those variables/3.

So 2 questions:

1: is this the right way to handle dynamically sized widgets. Or is this the wrong way to handle a problem like this?

2: Any ideas why those 2-4 variables are all coming back as 0?

  • 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-28T07:27:11+00:00Added an answer on May 28, 2026 at 7:27 am

    I would advise against doing pixel-perfect designs on android, due to the vast amount of resolutions and densities you have to deal with.

    My suggestion would be to look at android:layout_width/height="wrap_content" and android:layout_weight="INTEGER" that will help you make floating 3×3. You can also achieve this with a GridView

    • 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 do is make a very simple vertical bullet projectile
Basically i'm trying to build a comment system. The user looks at a photo
Basically I have two models: User and Godfather. The godfather table has three columns:
Basically i've a table for my users (it's nightclub website) and now i'm trying
Basically I'm going to go a bit broad here and ask a few questions
Basically I am trying to restart a service from a php web page. Here
Basically, I'm trying to tap into the Soap pipeline in .NET 2.0 - I
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
Basically, what I'm trying to create is a page of div tags, each has
Basically what I am doing is giving a user a list of terms via

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.