Set programmatically margin values on a custom view in a FrameLayout
<p>I define a view. This view contains a picture and the user can interact with. I define a FrameLayout in my main layout and i add this view programmatically in this FrameLayout.</p>

<p>In the View constructor, i define a MarginLayutParams to put this view on the center of te screen. The code is :</p>

<pre><code>mLayoutParams = new MarginLayoutParams(picture.getWidth(), picture.getHeight);
mLayoutParams.setMargins(toCenterX, toCenterY, 0, 0);
setLayoutParams(mLayoutParams);
</code></pre>

<p>The margin values don't works... The view is correctly resize to width and height defines but the view isn't scale to the center of the view by the margin values...</p>

<p>Edit : </p>

<p>Schemas of my views :</p>

<pre><code>                         -&gt; View1 (i want sclae this view to the center)
Activity -&gt; FrameLayout  -&gt; View2 (i want scale this view under the view 1)
                         -&gt; View3 (i want scale this view at the top right)
</code></pre>

<p>Here a sample of my ViewGroup. I implement a ViewGroup to manage all views :</p>

<pre><code>public class MainView extends ViewGroup {

public BackgroundView mBackgroundWheelArea;
public BackgroundView mBackgroundLabelArea;
public WheelCoreView wheelCoreArea;
public LabelView labelArea;

public WheelOfFortuneActivity mActivity;

public MainView(Context pContext) {
    super(pContext);
    mActivity = (WheelOfFortuneActivity) pContext;
    mBackgroundWheelArea = new BackgroundView(pContext, R.drawable.menu_background);
    wheelCoreArea = new WheelCoreView(pContext, mActivity.fromPixelToDp(mBackgroundWheelArea
            .getBackgroundHeight()), mActivity.fromPixelToDp(mBackgroundWheelArea
            .getBackgroundWidth()));
    labelArea = new LabelView(pContext, "Web");
    mBackgroundLabelArea = new BackgroundView(pContext, R.drawable.menu_background_label);
    this.addView(wheelCoreArea, 0);
}

@Override
protected void onLayout(boolean pChanged, int pL, int pT, int pR, int pB) {
    final int count = getChildCount();
    for (int i = 0; i &lt; count; i++) {
        View child = getChildAt(i);
        child.layout(100, 100, 0, 0);
    }

}

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    child.draw(canvas);
    return true;
}

}
</code></pre>

<p>But the wheelCoreArea view no move from the top left corner ! :(</p>

<p>Can you help me ?</p>

<p>Regards.</p>
