Robby Smet
Robby Smet

Reputation: 4661

Difference between setting layoutparams direct or in addView

I was wondering if there is a difference between

LinearLayout.LayoutParams separatorParams = new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

TextView separator = new TextView(context);
separator.setLayoutParams(seperatorParams);

this.addView(separator);

Or

LinearLayout.LayoutParams separatorParams = new LinearLayout.LayoutParams(
                        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

TextView separator = new TextView(context);

this.addView(separator,separatorParams);

Upvotes: 3

Views: 273

Answers (2)

Chris.Jenkins
Chris.Jenkins

Reputation: 13129

Absolutely none.

this.addView(separator); Will grab the params from the child or generate it.

Where as: this.addView(separator,separatorParams); Will use the params then add it to the layout anyway.

Have a look at the source here

Upvotes: 2

njzk2
njzk2

Reputation: 39406

According to the source code, it basically makes no difference since addView(View view) calls addView(view, view.getLayoutParams())

Upvotes: 2

Related Questions