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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:19:14+00:00 2026-06-09T19:19:14+00:00

I’ve hit this from various different angles. Basically the gist is this: I’ve layed

  • 0

I’ve hit this from various different angles. Basically the gist is this:

I’ve layed out a template in XML for an interface which NEEDS to be run programmatically, so it’s going to be populated dynamically during the run.

The problem here, is that the XML TextView has quite a few layout tweaks (which work) and are necessary. But if I actually set them in code, the TextView doesn’t even show up.

(The TextView, by the way, is nested inside a TableRow, thus the call to weight.)
The XML template I designed first, to use as reference for the code is this, and it works just fine:

<TextView
  android:id="@+id/txtviewWhiteBox"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_weight="1.0"
  android:background="@drawable/textview_9patch_white"
  android:gravity="center"
  android:text="75"
  android:textColor="@android:color/black"
  android:layout_margin="20dp"
  android:padding="20dp"
  android:textSize="40dp" />

Like I said, that lays out perfectly.
When I run the same layout in code though, and apply LayoutParams, the TextView disappears.

Here’s the relevant snippet:

int textViewExampleID = 9001;

private TextView txtviewExample = new TextView(this);

private void buildTextView(){   
    LayoutParams paramsExample = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1.0f);
    txtviewExample.setId(textViewExampleID);
    txtviewExample.setBackgroundResource(R.drawable.textview_9patch_white);
    txtviewExample.setGravity(Gravity.CENTER);
    txtviewExample.setTextColor(getResources().getColor(android.R.color.black));
    paramsExample.setMargins(20, 20, 20, 20);
    txtviewExample.setPadding(20, 20, 20, 20);
    txtviewExample.setTextSize(40); 
    txtviewExample.setText("customExample");

    //if I comment out the following line, this TextView displays.
    //if I leave it in, it doesn't display.
    txtviewExample.setLayoutParams(paramsExample);
}

I realize there’s all sorts of available classes for LayoutParams, and I’ve been playing with them all
LinearLayout.LayoutParams, TableView.LayoutParams, RelativeLayout.LayoutParams, LayoutParams just by itself…
No matter which one I try, any attempt at calling “setLayoutParams” renders the entire TextView gone.
I’ve scoured the forums here, and haven’t quite found the answer. This can’t be THAT uncommon.

  • 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-09T19:19:15+00:00Added an answer on June 9, 2026 at 7:19 pm

    well, that was painful but I finally got it figured out.
    The most important thing to remember (that I just realized) is that of all the myriads of LayoutParams, you need to use the one that relates to the PARENT of the view you’re working on, not the actual view.

    So in my case, I was trying to get the TextView margins working, but it was being put inside a TableRow. The one simple change was ensuring that the type of LayoutParams being used were the ones for TableRow:

    private void buildTextView(){   
        // the following change is what fixed it
        TableRow.LayoutParams paramsExample = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1.0f);
        txtviewExample.setId(textViewExampleID);
        txtviewExample.setBackgroundResource(R.drawable.textview_9patch_white);
        txtviewExample.setGravity(Gravity.CENTER);
        txtviewExample.setTextColor(getResources().getColor(android.R.color.black));
        paramsExample.setMargins(20, 20, 20, 20);
        txtviewExample.setPadding(20, 20, 20, 20);
        txtviewExample.setTextSize(40); 
        txtviewExample.setText("customExample");
        txtviewExample.setLayoutParams(paramsExample);
    }
    

    Thanks guys, hopefully this will come in handy for somebody else down the line, as I saw a lot of semi-related questions in the forums here, but not one that really defines the problem.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.