简体   繁体   English

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

[英]Android: Recyclerview not resizing when softinput keyboard appears

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. customview 包含一个edittext,在它的正下方是一个高度为match_parent 的recyclerview。 When the user gets focus on the edittext a softinput keyboard appears.. unfortunately this keyboard hides half the recyclerview underneath it.当用户关注edittext时,会出现一个软输入键盘。不幸的是,这个键盘隐藏了它下面的一半recyclerview。 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.我希望 recyclerview 调整到屏幕的剩余可见高度(在edittext下),以便列表中的项目不会被键盘隐藏。

I've tried setting adjustresize for the activity in the manifest but it has no effect:我已经尝试为清单中的活动设置adjustresize,但它没有效果:

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"

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

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).我检查了活动、片段、自定义视图和连接的每个适配器,以确保我没有在任何地方调用 getWindow(我没有)。

The customview is inflated at runtime from a viewstub. customview 在运行时从viewstub 膨胀。 Could this have a connection?这可能有联系吗?

Edit:编辑:

contents of the parent:父母的内容:

<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>

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>

Showing the keyboard thusly:如此显示键盘:

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);

This will take care of recyclerview resizing.这将负责 recyclerview 调整大小。

window.decorView.setOnApplyWindowInsetsListener { view, insets ->
    val insetsCompat = toWindowInsetsCompat(insets, view)
    mainNavigation.isGone = insetsCompat.isVisible(ime())
    view.onApplyWindowInsets(insets)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM