I\'ve got the following problem: I implemented a HorizontalScrollView
which contains in one case a LinearLayout
and an ImageView
. In t
Do somethings like this :
LayoutParams lp = new LayoutParams();
lp.gravity= Gravity.CENTER_HORIZONTAL;
myImg.setLayoutParams(lp);
UPDATE : Another way to do this :
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.weight = 1.0f;
params.gravity = Gravity.CENTER;
imageView.setLayoutParams(params);
I think , this one will work for you
FrameLayout.LayoutParams layoutParams = new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams1.gravity(YourGravity);
yourImage.setLayoutParams(layoutParams);
Put the ImageView
in a FrameLayout
like this:
Removed extra code
ImageView image = new ImageView(mContext);
image.setLayoutParams(new FrameLayout.LayoutParams(width, height, gravity));
More info here.