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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:44:16+00:00 2026-05-25T21:44:16+00:00

I am stuck up here trying to get the width of a TextView in

  • 0

I am stuck up here trying to get the width of a TextView in a Table Row after setting some random text to it.
I am using the getWidth(), but it returns zero always. Is there a way to find out the width of a dynamically created TextView.

Here is my code.

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    customer_id=(TextView)findViewById(R.id.customer_id);
    comapny_name=(TextView)findViewById(R.id.compnay_name);
    line1=(ImageView)findViewById(R.id.line1);




    TableLayout tl=(TableLayout)findViewById(R.id.linlay);
    TableRow tr1 =null;
    for(int i=0;i<20;i++)
    {
        tr1 = new TableRow(this);
    tr1.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
    TextView textview = new TextView(this);
    textview.setText("data");
    textview.setTextColor(Color.YELLOW);
    textview.setTextSize(30);


    TextView textview1 = new TextView(this);
    textview1.setText("data1");
    textview1.setTextColor(Color.YELLOW);
    textview1.setTextSize(30);

    tr1.addView(textview);
    tr1.addView(textview1);
    tl.addView(tr1);

int width=textview.getWidth();
Log.i("Width",width+"");

}     
  • 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-25T21:44:16+00:00Added an answer on May 25, 2026 at 9:44 pm

    Ok actually the layout is inflated but not yet drawn so in order to get width you will have to

    @Override 
    public void onWindowFocusChanged(boolean hasFocus) 
    { 
         // TODO Auto-generated method stub 
         super.onWindowFocusChanged(hasFocus);
         System.out.println("...111Height..."+textview.getMeasuredWidth()); 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck here and hope to get some guidance on this. I'm trying
I'm trying to get AppFabric monitoring to work but I'm stuck here. Events are
I am stuck here with Linq query... I am just trying to get my
I'm trying to get AppFabric monitoring to work but I'm stuck here. Events are
I am stuck with a small problem here.. What i am trying to do
I'm stuck here: I need to get the values of org.jboss.system.server.ServerInfo With the code
I'm trying to get audio files to crossfade with phonon. I'm using PyQT4. I
I've been trying to get an NHibernate ICompositeUserType mapping to work. But am stuck
I am trying to write merge sort and stuck here. What is the problem
I have a text file with some data in it, and I'm trying to

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.