Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"

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.

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

The customview is inflated at runtime from a 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);
}
like image 972
Jon Avatar asked Aug 12 '15 11:08

Jon


1 Answers

Don't do anything in manifest file. Just use

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

This will take care of recyclerview resizing.

like image 170
karandeep singh Avatar answered Oct 22 '22 15:10

karandeep singh