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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:36:48+00:00 2026-06-03T05:36:48+00:00

Does ViewGroup.addView clones LayoutParams data into inside or links to it? May I reuse

  • 0

Does ViewGroup.addView clones LayoutParams data into inside or links to it? May I reuse the same instance of LayoutParams with multiple calls to addView() with different views?

There is nothing about it in apidoc.

WOW

The answer is NO (checked experimentally):

public class SymbolPadActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    RelativeLayout.LayoutParams labelParams;

    /*
     * This block to reuse is not working
    labelParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    labelParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    labelParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    */


    RelativeLayout mover = new RelativeLayout(this);

    TextView textView;
    for(int leftMargin = 0; leftMargin<3000; leftMargin += 100) {
        for(int topMargin=0; topMargin<800; topMargin += 40) {

            // I can't omit these 3 lines 
            labelParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            labelParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
            labelParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);

            labelParams.leftMargin = leftMargin;
            labelParams.topMargin = topMargin;

            textView = new TextView(this);
            textView.setText("(" + leftMargin + "," + topMargin + ")");
            mover.addView(textView, labelParams);

        }
    }




    RelativeLayout.LayoutParams moverParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    moverParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    moverParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    moverParams.leftMargin = 0;
    moverParams.topMargin = 0;

    RelativeLayout stator = new RelativeLayout(this);
    stator.addView(mover, 0, moverParams);

    setContentView(stator);


}

}

  • 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-03T05:36:50+00:00Added an answer on June 3, 2026 at 5:36 am

    There is nothing about it in apidoc.

    This means you need to make the more conservative choice, no matter what the current implementation is, as the implementation could change.

    Hence, you need to assume that it is not safe to reuse an instance of LayoutParams with different Views.

    For what it’s worth, as far as I can tell, that is true anyway – ViewGroup doesn’t make a copy.

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

Sidebar

Related Questions

Does anyone how to set a custom library version, when compiling with the gmcs
Does $this->db->insert_batch(); insert with 1 table connection or does it insert each row separately
Does anyone know, what an XMLHttpRequest enables a web page to do, which cannot
Does any one know how I can have this happen in a windows phone
Does the JavaScript below allow a webpage load quicker opposed to the a standard
Does anybody know what i mean? In fullscreen mode of the new camera app
Does ScanResult.level (signal level) have a max and min value? I want to show
Does this below class is immutable? class Immutable { private int x; Immutable(int value)
Does it (and in what way) effect performance to have a complex Layout hierarchy?
Does anyone know how to perform or have a good reference for doing an

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.