In some cases, you have to create and style a LinearLayout or RelativeLayout programmatically. Attributes that you can programmatically apply to the layout can be background color, layout width, height, margins, orientation, layout gravity, paddings, and so son.
LinearLayout layout = new LinearLayout(MainActivity.this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams (LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.setMargins(15, 5, 5, 5); layout.setLayoutParams(params);
layout.setHorizontalGravity(Gravity.CENTER_HORIZONTAL); layout.setPadding(10, 10, 5, 5);
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: