Monday, April 25, 2011

Android Tips - Using Layout Param

Layout Param is used to change the layout properties. You can create a layout instance and assign to required view.

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

Sample Code

LinearLayout.LayoutParams mLayoutParam = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Button mButton = new Button(this);
mButton.setLayoutParams(layoutParam);

The above code works fine but this is not a current solution. It should like the below code

Button mButton = new Button(this);
ViewGroup.LayoutParam mLayoutParam= mButton.getLayoutParams();
mLayoutParam.height = ViewGroup.LayoutParams.FILL_PARENT


Thanks to Ashok , I have done the mistake and corrected me

No comments:

Post a Comment