Long Smith
Long Smith

Reputation: 1411

Android relative layout positioning

I have this code,

    DisplayMetrics display = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(display);
    _screenHeight = display.heightPixels;

    ...

    int eFieldTopMargin = (int)(_screenHeight*0.25);
    int pFieldTopMargin = (int)(_screenHeight*0.25+90);
    int signInButtonTopMargin = (int)(_screenHeight*0.25+180);

    RelativeLayout.LayoutParams lParamsForEField = (LayoutParams) eField.getLayoutParams();
    RelativeLayout.LayoutParams lParamsForPField = (LayoutParams) pField.getLayoutParams();
    RelativeLayout.LayoutParams lParamsForSignInButton = (LayoutParams) signInButton.getLayoutParams();

    lParamsForEField.setMargins(0, eFieldTopMargin, 0, 0);
    eField.setLayoutParams(lParamsForEField);

    lParamsForPField.setMargins(0, pFieldTopMargin, 0, 0);
    pField.setLayoutParams(lParamsForPField);

    lParamsForSignInButton.setMargins(0, signInButtonTopMargin, 0, 0);
    signInButton.setLayoutParams(lParamsForSignInButton);

Could anyone tell me why I get this? Button is above text fields, though its top margin is more. Why button is above text fields, though its top margin is more?

Upvotes: 1

Views: 77

Answers (1)

Phantômaxx
Phantômaxx

Reputation: 38098

Add this line

lParamsForSignInButton(ALIGN_PARENT_TOP);

before

signInButton.setLayoutParams(lParamsForSignInButton);

Upvotes: 1

Related Questions