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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:02:54+00:00 2026-06-13T07:02:54+00:00

Every time I set the layout param of TextView to wrap content or fill

  • 0

Every time I set the layout param of TextView to wrap content or fill parent it’s not showing in the view, but when I set it to pixels it’s working why is that?

Here is the relevant code:

items = (LinearLayout) findViewById(R.id.llmain);
        tb = new TableLayout(MainActivity.this);

        tb.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        tb.setGravity(Gravity.CENTER);


            TableRow tr = new TableRow(MainActivity.this);
            ImageButton ima = new ImageButton(MainActivity.this);
            ImageButton imr = new ImageButton(MainActivity.this);
            TextView tvin = new TextView(this);

            TableRow.LayoutParams trp = new TableRow.LayoutParams();
            trp.setMargins(0, 0, 0, 10);
            tr.setLayoutParams(trp);
            tr.setGravity(Gravity.CENTER);

            ima.setBackgroundColor(Color.TRANSPARENT);
            ima.setImageResource(R.drawable.add);

            imr.setBackgroundColor(Color.TRANSPARENT);
            imr.setImageResource(R.drawable.remove);

            tvin.setWidth(100);
            tvin.setHeight(45);
            tvin.setGravity(Gravity.CENTER);
            tvin.setText(sil[i]);
            tvin.setBackgroundColor(Color.rgb(200, 0, 255));

            tr.addView(ima);
            tr.addView(tvin);
            tr.addView(imr);

            tb.addView(tr);

        items.addView(tb);

I tried using this

tvin.setLayoutParams(new LayoutParams(
            LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));

and this

tvin.setWidth(LayoutParams.FILL_PARENT);
tvin.setHeight(LayoutParams.FILL_PARENT);

but none of these work.

  • 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-13T07:02:55+00:00Added an answer on June 13, 2026 at 7:02 am

    Try:

    tvin.setLayoutParams(new TableRow.LayoutParams(
                LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT));
    

    and remove the tvin.setWidth and height.

    You should always set the layout params of view’s parent, TableRow in this case.
    MATCH_PARENT makes no difference but it’s a new name and you should be using it instead of FILL_PARENT.

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

Sidebar

Related Questions

Every time try to set the value of any variable in my model object,
Every time I start gdb, I immediately do: set print thread-events off It would
My UIButton is set to disappear every time my UITextField is done editing, I
I need to set the color of the font every time I add text
Many times I needed a set of pointers. Every time that happens, I end
Every time that I want to do a Layout, I'm getting a black layout
I know there are questions like: android-intent-bundle-always-null and intent-bundle-returns-null-every-time but there is no correct
Every time i reset & seed my database it wipes out the standard admin@example.com
Every time when I'm trying to load the .dll in my application, I'm getting
every time I open my Solution in Visual Studio it tries to communicate and

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.