I define the view. This view contains an image, and the user can interact with it. I define FrameLayout in my main layout, and I add this view programmatically to this FrameLayout.
In the View constructor, I define MarginLayutParams to place this view in the center of the screen. Code:
mLayoutParams = new MarginLayoutParams(picture.getWidth(), picture.getHeight); mLayoutParams.setMargins(toCenterX, toCenterY, 0, 0); setLayoutParams(mLayoutParams);
The field values ββdo not work ... The view correctly changes to the width and height, but the view does not scale to the center of the view according to the field values ββ...
Edit:
Schemes of my views:
-> View1 (i want sclae this view to the center) Activity -> FrameLayout -> View2 (i want scale this view under the view 1) -> View3 (i want scale this view at the top right)
Here is a sample of my ViewGroup. I am implementing a ViewGroup to manage all kinds of:
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 < 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; } }
But wheelCoreArea does not see movement from the upper left corner !: (
Can you help me?
Sincerely.