【发布时间】:2021-04-22 18:25:34
【问题描述】:
我想设置我的线性布局,它包含在键盘正上方的相对布局中。
为此,我将线性布局设置为 alignParentBottom="true" 并以编程方式设置底部边距等于键盘高度,但它不起作用
multipleMediaRelLyaout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
multipleMediaRelLyaout.getWindowVisibleDisplayFrame(r);
int screenHeight = multipleMediaRelLyaout.getRootView().getHeight();
keyboardH = screenHeight - r.bottom;
final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)edittextLinLayout.getLayoutParams();
params.bottomMargin=keyboardH ;//not working
//params.bottomMargin=800; its working
edittextLinLayout.setLayoutParams(params);
}
});
【问题讨论】:
-
你能发布你的xml布局吗?
-
很简单...
----
标签: android