Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6333357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:26:44+00:00 2026-05-24T18:26:44+00:00

I define a view. This view contains a picture and the user can interact

  • 0

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.

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

mLayoutParams = new MarginLayoutParams(picture.getWidth(), picture.getHeight);
mLayoutParams.setMargins(toCenterX, toCenterY, 0, 0);
setLayoutParams(mLayoutParams);

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…

Edit :

Schemas 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 a sample of my ViewGroup. I implement a ViewGroup to manage all views :

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 the wheelCoreArea view no move from the top left corner ! 🙁

Can you help me ?

Regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:26:44+00:00Added an answer on May 24, 2026 at 6:26 pm

    You should override onLayout() method and set the view bounds manually instead of setting the margins.

    Call view.layout(top, left, right, bottom); Maintain the bounds in member variables.

    If the size of this view also changes you may need to override the onMeasure method too.

    Edit

    Try this formula to calculate the view placement points.

    viewLeft = displayWidth()/2 - viewWidth/2;
    viewTop = displayHeight()/2 - viewHeight/2;
    

    Call view.layout(viewLeft , viewTop , viewLeft + viewWidth, viewTop + viewHeight);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC view which contains checkboxes for user-defined categories. <td><% foreach
I have a main navigationController controlled on the app's delegate and this navigationController contains
Short question - how do you define your view models? Here are some of
I understand that we need to create MXML file to define a view. Suppose
I am using the lxml library to define a variable (category) in a view.
If I want a orthograpic view of the region (-10,-1),(-2,-1),(-2,-7),(-10,-7) how do I define
I have a RelativeLayout defined in an xml layout file named 'myview.xml' which contains
I want to generate a dynamic site using Zend_Layout. My layout (/application/layouts/scripts/layout.phtml) contains the
I have a solution with following projects GUI (contains views) ViewModels (contains all view
Hi all I am trying to set up a view that lets the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.