set width programmatically android code example
Example 1: how to set view width programmatically in android
View view = findViewById(R.id.nutrition_bar_filled);
LayoutParams layoutParams = view.getLayoutParams();
layoutParams.width = newWidth;
view.setLayoutParams(layoutParams);
Example 2: set height of layout programmatically android
LinearLayout layout = findViewById(R.id.numberPadLayout);
LayoutParams params = layout.getLayoutParams();
params.height = 100;
params.width = 100;
layout.setLayoutParams(params);