Pregunta

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?

¿Fue útil?

Solución

Add this line

lParamsForSignInButton(ALIGN_PARENT_TOP);

before

signInButton.setLayoutParams(lParamsForSignInButton);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top