You Need to add LayoutParams
for your ChildView
Like:
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
yourCalculatedWidth, LayoutParams.FILL_PARENT);
params.gravity=Gravity.CENTER_HORIZONTAL;
imgView.setLayoutParams(params);