Hey,
i'm currently coding an app, which has to add/remove interface elements on the fly. When one clicks on a Spinneritem, the selected item is added to a container with a delete button to remove it if necessary.

The problem is, that the needed views and the layout are created directly in the javacode using this code:

I'm now wondering how it is possible to add layoutparams to the new views like in an xml file (android:width="fill_parent" etc.) or if it is not the better way to read this layoutpart from an xml and change only the needed parameters. And if yes, how to do it (both ways).

Hi michael,For any View in Android , u should use setLayoutParams(width, height) to set its dimensions. I suggest u use this method to set a view's dimensions if ur views are to be generated at runtime ( based on a UI event such as a button click ) . This is more flexible than inflating the layouts from XML files ( unless u use hard-coded layouts ) .Examples : textView.setLayoutParams(60, 100 ); textView.setLayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT );

thank you, thats good to know. just thought it would be a better style to keep all the layouts in the XMLs. Where can I now change the params like layout_weight or paddingTop. I can not find it in the LayoutParams Object.