我有这段代码,
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);
有人能告诉我为什么会这样吗?按钮位于文本字段上方,但其上边距更大。
答案 0 :(得分:1)
添加此行
lParamsForSignInButton(ALIGN_PARENT_TOP);
之前
signInButton.setLayoutParams(lParamsForSignInButton);