【问题标题】:I want scroll RecyclerView item above to keyboard when keyboard open我想在键盘打开时将上面的 RecyclerView 项目滚动到键盘
【发布时间】:2019-09-25 04:27:48
【问题描述】:

我在recyclerview 项目中有edittext,当用户单击recyclerview 行内的edittext 时,我希望将上面的recyclerview 项目滚动到键盘。我在 Instagram 提要列表中看到了相同的内容,但我无法像 Instagram 那样实现。检查 Instagram 屏幕截图我将要实现的目标。

[enter image description here][1]KeyboardUtils.registerSoftInputChangedListener(getActivity(), new KeyboardUtils.OnSoftInputChangedListener() {
        @Override
        public void onSoftInputChanged(int height) {
         enter image description here
            recyclerViewPostList.smoothScrollBy(0, height);
        }
    });

【问题讨论】:

  • 是的,我正在尝试相应地滚动 x 和 y 键盘高度,但没有得到很好的输出。 KeyboardUtils.registerSoftInputChangedListener(getActivity(), new KeyboardUtils.OnSoftInputChangedListener() { @Override public void onSoftInputChanged(int height) { recyclerViewPostList.smoothScrollBy(0, height); } });

标签: android android-recyclerview android-edittext


【解决方案1】:

将此行添加到您的清单中,如下所示添加到您的活动标签中。

 android:windowSoftInputMode="adjustResize"

或者您也可以从您的活动中添加它,方法是在您的活动的代码oncreate 下方添加

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

对于片段

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

【讨论】:

    猜你喜欢
    • 2020-06-09
    • 2018-05-08
    • 1970-01-01
    • 2020-12-06
    • 2016-12-17
    • 2022-10-09
    • 1970-01-01
    • 2021-10-16
    • 2017-08-06
    相关资源
    最近更新 更多