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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:59:40+00:00 2026-05-25T19:59:40+00:00

I noticed there are two ways to add LayoutParams programmatically to any view and

  • 0

I noticed there are two ways to add LayoutParams programmatically to any view and am curious to ask do they have different meanings as well.

Example 1

In this example, setting LayoutParams directly to the button.

LinearLayout parent = new LinearLayout(this);
Button btnNew = new Button(this);
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
button.setLayoutParams(params);
parent.addView(btnNew);

Example 2

In this example adding layoutparams to button when it’s being added to the parent view.

LinearLayout parent = new LinearLayout(this);
Button btnNew = new Button(this);
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
parent.addView(btnNew, params);

What’s different in both?

  • 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-25T19:59:40+00:00Added an answer on May 25, 2026 at 7:59 pm

    There is no difference. If you check the android source code, it specifies that if no layout params are specified, the defualts params of the view group are set. When you use the method

    addView(child,params);
    

    It calls another method named addViewInner which just sets the params object to the child object.

    The source code from the ViewGroup.java can be seen here

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

Sidebar

Related Questions

I've noticed that there are two different ways to load nib/xib files: via the
I noticed recently that there are two ways to print multiple statements in PHP.
I noticed there are two ways to create nice generic friendly access to nhibernate.
In javascript, I have noticed two ways of throwing an error: 1) throw An
When I run get-user|get-member in powershell with the exchange add-in I noticed there is
In WPF, there are two ways to set the focus to an element. You
I'm trying to fetch some HTML from various blogs and have noticed that different
There are two methods which I noticed while designing child tables Method 1 Example:
I am using IntelliJ 10 Comnunity Edition, and I noticed there are two refactoring
I noticed that there are two debug perspectives in Eclipse that is setup for

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.