How to set gravity (or margins) of ImageView using code?

Posted by mastojun on Stack Overflow See other posts from Stack Overflow or by mastojun
Published on 2010-04-11T19:11:22Z Indexed on 2010/04/11 19:13 UTC
Read the original article Hit count: 205

Filed under:

Hi.

I want to add ImageView to FrameLayout with Gravity or margins. but FramLayout and ImageView has no method about that(Actually, I can't found that). Reason that selects Framelayout is to put ImageView on ImageView.

Help me plz. It is emergency for me to find solution.

thx.

Bellow is my code which help understanding my question.

FrameLayout imageFrame = new FrameLayout(mContext);
imageFrame.setLayoutParams(new GridView.LayoutParams(158, 158));

ImageView frame = new ImageView(mContext);
frame = new ImageView(mContext);
frame.setLayoutParams(new LayoutParams(158, 158));
frame.setScaleType(ImageView.ScaleType.CENTER_CROP);
frame.setImageResource(R.drawable.image_frame_n);

ImageView image = new ImageView(mContext);
image.setLayoutParams(new LayoutParams(148, 148));
image.setScaleType(ImageView.ScaleType.CENTER_CROP);
image.setImageResource(mThumbIds[position]);
// image is needed to have a margin or gravity to be positioned at center

imageFrame.addView(image);
imageFrame.addView(frame);

© Stack Overflow or respective owner

Related posts about android