tags:

views:

613

answers:

1

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.

Below 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 of imageFrame

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

Try:

image.setLayoutParams(new FrameLayout.LayoutParams(width, height, gravity));

More info:

http://developer.android.com/reference/android/widget/FrameLayout.LayoutParams.html

hgpc
Oh~ Thanks a lot!! :)
Mastojun
FrameLayout, among others, has a setMargins method.
drawnonward
You're welcome mastojun. Please don't forget to accept the best answer.
hgpc
That Method witch has a setMargins is not work in my code T^T.And I applied above code, but It is not matching my expectation. so I use different way. (framelayout (imageview, talbelayout(imageview))); tablelayout has a padding. terrible!
Mastojun