Abhishek Sharma
Abhishek Sharma

Reputation: 619

adjustResize not working with EditText view inside a fragment layout

I have a full-screen activity with certain layout elements that hide to give way to a fragment inside a container (FrameLayout). Layout is as shown below:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/home_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/closing_background"
    android:orientation="vertical"
    tools:context="com.example.activities.MainActivity">

        <FrameLayout
            android:id="@+id/dim"
            android:alpha="0"
            android:fitsSystemWindows="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/dimBg" />

        <RelativeLayout
            android:id="@+id/header_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="48dp"
            android:layout_alignParentTop="true">

            <ImageView
                android:id="@+id/menu"
                android:visibility="visible"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_marginStart="24dp"
                android:background="@drawable/ic_menu_black_24dp"/>

            <ImageView
                android:id="@+id/logo_img"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:scaleType="fitXY"
                android:src="@drawable/ic_app_logo_black" />

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/header_layout"
            android:orientation="vertical"
            android:layout_marginTop="26dp">

            <FrameLayout
                android:id="@+id/fragmentContainer"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </RelativeLayout>

        <LinearLayout
           android:id="@+id/first_layout"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_below="@id/header_layout"
           android:visibility="gone"
           android:orientation="vertical"
           android:layout_marginTop="93dp">

             <--other layout elements here-->
        </LinearLayout>
</RelativeLayout>

The fragment layout is as shown below:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/parentLayout"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:background="@android:color/transparent">

        <RelativeLayout
            android:id="@+id/rootView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipChildren="false">

            <TextView
                android:id="@+id/description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="6dp"
                android:layout_alignParentTop="true"
                android:textSize="18sp"
                android:lineSpacingMultiplier="1.5"/>

            <com.example.MyCustomRecyclerView
                android:id="@+id/customRecyclerView"
                android:layout_below="@id/description"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginBottom="72dp"
                android:clipToPadding="false">

            </com.example.MyCustomRecyclerView>

            <include layout="@layout/input_view"
                tools:visibility = "gone"/>

        </RelativeLayout>

</ScrollView>

As you can see, in my fragment layout, I am including another layout called input_view. The layout file for this is shown below:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_slide_up_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.activities.MainActivity"
    tools:showIn="@layout/activity_main">

    <RelativeLayout
        android:id="@+id/slideResponseView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="26dp"
        android:background="@drawable/rounded_up_corners_bg">

        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/pullDownArrow"
            android:text="@string/response_view_title"
            android:gravity="center_horizontal"
            android:layout_marginTop="16dp"
            android:textAllCaps="false"/>

        **<EditText
            android:id="@+id/response_view_input"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/title"
            android:layout_margin="10dp"
            android:gravity="top"
            android:padding="10dp"/>**

        <ImageView

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            app:srcCompat="@drawable/ic_keyboard_arrow_down_black_24dp"
            android:id="@+id/pullDownArrow"
            android:layout_marginTop="15dp"/>

    </RelativeLayout>

</RelativeLayout>

This is a slideUp panel obtained from this source: https://github.com/mancj/SlideUp-Android, which largely is an edittext view that slides up on click event on the recyclerview item. The slider panel occupies 2/3rd of the screen space in portrait mode (and my app is portrait only). Now when I click on the EditText view on this slider panel to enter any text, I want this view to resize when the soft keyboard opens up from below it. I tried a few things suggested on SO like wrapping the root layout with a ScrollView but still doesn't work.

Also, the activity in manifest file includes the below:

android:windowSoftInputMode="adjustResize"

As mentioned above, the activity is a full screen activity which I am programmatically handling using below code:

requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                    WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

View decorView = getWindow().getDecorView();

int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
decorView.setSystemUiVisibility(uiOptions);

Can someone please guide me here? If the question or part of my code is not clear, please let me know so I can elaborate a little more.

Thanks,

AB

Upvotes: 4

Views: 4053

Answers (1)

Mushfique Monim
Mushfique Monim

Reputation: 164

Replace ScrollView with NestedScrollView. Also replace RelativeLayout with ConstraintLayout. Other code is ok.

Upvotes: 1

Related Questions