Android:当软输入键盘出现时,Recyclerview不会调整大小

Jon*_*Jon 5 java user-interface android android-recyclerview

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

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

android:windowSoftInputMode="adjustResize"
Run Code Online (Sandbox Code Playgroud)

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

android:theme="@style/Theme.AppCompat.NoActionBar"
Run Code Online (Sandbox Code Playgroud)

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

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

自定义视图在运行时从视图存根中膨胀.这有联系吗?

编辑:

父母的内容:

<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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

这样显示键盘:

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);
}
Run Code Online (Sandbox Code Playgroud)

kar*_*ngh 8

不要在清单文件中做任何事情.只是用

((LinearLayoutManager)recyclerView.getLayoutManager()).setStackFromEnd(true);
Run Code Online (Sandbox Code Playgroud)

这将负责recyclerview的大小调整.

  • 你是我的神。谢谢 ! (2认同)