【问题标题】:How to set view to above of the keyboard?如何将视图设置为键盘上方?
【发布时间】: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


【解决方案1】:

在你的清单文件中使用这个 'android:windowSoftInputMode="adjustPan" '。试试下面的解决方案 https://stackoverflow.com/a/63816981/3916792

【讨论】:

  • 不想调整,它分散了主要RelativeLayout中包含的其他视图
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-07
  • 1970-01-01
  • 2016-02-03
  • 1970-01-01
  • 2015-10-24
  • 2020-06-09
  • 2015-01-02
相关资源
最近更新 更多