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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:34:56+00:00 2026-05-26T03:34:56+00:00

I believe you can set layout_width and layout_height to textview element dynamically using something

  • 0

I believe you can set layout_width and layout_height to textview element dynamically using something like:

LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
centimeterLayout.addView(textview, lparams);

But – how do I set the layout width and height in other units – e.g. I want to set the layout width of my text view to 20 mm. How do I do that?

  • 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-26T03:34:56+00:00Added an answer on May 26, 2026 at 3:34 am

    LayoutParams either take one of the constants (FILL_PARENT, WRAP_CONTENT) or a pixel value. Since you want to use millimeters, you have to convert a millimeter dimension to a pixel dimension. Doing so is pretty easy:

    Resources r = getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 20, 
                                         r.getDisplayMetrics());
    

    In this example, 20 mm are converted into a pixel dimension that you can use in your LayoutParams. You can use other dimensions too, such as TypedValue.COMPLEX_UNIT_DIP for dp/dip¹. Just change the constant in the arguments. The android doc has a list of useable dimensions.

    ¹ Density independend pixels, a highly recommended dimension that adjusts to the many different screen sizes and densities. Using mm isn’t the best way to do things, since your text will probably look okay on a big screen and fill a big portion of a small screen, or the other way around – which is not ideal. I also recommend sp for font sizes. See the dimension list for details.

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

Sidebar

Related Questions

Seems so basic, I can't believe I don't know this! I just need a
There gotta be an easy way to do this, I can't believe there's none.
I've been raised to believe that if multiple threads can access a variable, then
I always believe they did, but seeing some answers here make me doubt... Can
I believe strongly in using unit-tests as part of building large multi-platform applications. We
Is there a way I can set a div background color in hiccup? Here
I have a property like so public decimal? MyProperty { get; set; } ,
This is a very simple setup, I can't believe but I didn't find anybody
How can I set up a business facebook page that when a user enters
I have searched for this and can't believe I can't find it. Perhaps I've

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.