Android:当软输入键盘出现时,Recyclerview不会调整大小 [英] Android: Recyclerview not resizing when softinput keyboard appears

查看:1244
本文介绍了Android:当软输入键盘出现时,Recyclerview不会调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含片段的活动,片段包含自定义视图。 customview包含一个edittext,并在其下方是一个高度为match_parent的recyclerview。当用户专注于edittext时,会出现一个软输入键盘。不幸的是,这个键盘隐藏了它下面的一半回收视图。我希望recyclerview调整大小到屏幕的剩余可见高度(在edittext下),这样列表中的项目不会被键盘隐藏。

I have an activity that contains a fragment and the fragment contains a customview. The customview contains an edittext and directly below it a recyclerview with height of match_parent. When the user gets focus on the edittext a softinput keyboard appears.. unfortunately this keyboard hides half the recyclerview underneath it. I want the recyclerview to resize to the remaining visible height of the screen (under the edittext) so that items in the list aren't hidden by the keyboard.

我已尝试为清单中的活动设置adjustresize,但它没有效果:

I've tried setting adjustresize for the activity in the manifest but it has no effect:

android:windowSoftInputMode="adjustResize"

我试过设置我的应用基本主题的主题(如果我的自定义主题中的某些内容导致问题) - 没有效果:

I've tried setting my app theme to a base theme (in case something in my custom theme was causing a problem) - no effect:

android:theme="@style/Theme.AppCompat.NoActionBar"

我已经检查过以确保没有framelayouts在层次结构的任何地方到必须调整大小的视图(我读了一个SO线程,这可能是一个问题) - 没有。

I've checked to make sure there are no framelayouts anywhere down the hierarchy to the view that has to be resized (I read an SO thread that it could be a problem) - there are none.

我已经检查了活动,片段,自定义视图和连接的每个适配器,以确保我没有在任何地方调用getWindow(我不是)。

I've checked the activity, the fragment, the customview and every adapter connected to make sure that I'm not calling getWindow anywhere (I'm not).

自定义视图在运行时膨胀从viewstub。这有连接吗?

The customview is inflated at runtime from a viewstub. Could this have a connection?

编辑:

父母的内容:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parent_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
...


    <ViewStub
        android:id="@+id/viewstub_outername"
        android:layout="@layout/viewstub_thatIneed"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</RelativeLayout>

viewstub的内容:

contents of the viewstub:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/viewstub_root"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:background="@android:color/white"
    >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp"
        android:visibility="invisible"
        />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp"
        android:visibility="invisible"
        />

</RelativeLayout>

如此显示键盘:

public static void showSoftKeyboard(Activity activity) {
    View view = activity.getCurrentFocus();
    InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}


推荐答案

不要做任何事清单文件。只需使用

Don't do anything in manifest file. Just use

((LinearLayoutManager)recyclerView.getLayoutManager()).setStackFromEnd(true);

这样可以处理Recyclerview的大小调整。

This will take care of recyclerview resizing.

这篇关于Android:当软输入键盘出现时,Recyclerview不会调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆