1

I am having issue with windowSoftInputMode="adjustResize" and setVisibility(View.VISIBLE). adjustResize was working as expected until visibility of a View was changed.

So, as long as I don't change visibility of anything programmatically adjustResize is working as expected but as soon as visibility of anything is changed it stops resizing the layout.

AndroidManifest.xml

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

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity
            android:name=".view.activity.MainActivity"
            android:theme="@style/AppTheme"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="Main_ACTIVITY" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

fragment.xml

<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:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context="ABC.view.fragment.Fragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.2"
            android:gravity="center">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/circleImg"
                style="@style/AppTheme.CircleImgList"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_centerVertical="true"
                android:layout_centerHorizontal="true"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.8"/>

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@color/colorPrimary"
        android:orientation="horizontal"
        android:layout_gravity="bottom"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/relativeLayout">

        <EditText
            android:id="@+id/editName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:textColor="@color/white"
            android:hint="Enter Your Name"
            android:textColorHint="#AAFFFFFF"
            android:textSize="25sp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginRight="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:inputType="textCapWords"
            android:maxLines="1"
            android:layout_gravity="start"
            android:layout_centerVertical="true"/>

        <TextView
            android:id="@+id/nextButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="NEXT"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:textSize="20sp"
            android:textColor="@color/white"
            android:layout_marginEnd="20dp"
            android:layout_marginRight="20dp"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:clickable="true"
            android:visibility="gone"/>

    </RelativeLayout>

</RelativeLayout>

And onViewCreated of Fragment.java

public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    mCircleImgView = view.findViewById(R.id.circleImg);
    mEditName = view.findViewById(R.id.editName);
    mNextButton = view.findViewById((R.id.nextButton));

    mCircleImgView.setImageURI(mImageURI);

    mEditName.requestFocus();
    InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imgr.showSoftInput(mEditName, InputMethodManager.SHOW_IMPLICIT);

    //Change visibility of mNextButton
    mEditName.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable s) {}

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String text = mEditName.getText().toString();
            if (text.length() >= 1) {
                mNextButton.setVisibility(View.VISIBLE);
            }
            else {
                mNextButton.setVisibility(View.GONE);
            }
        }
    });
}

Gif of how it stops to resize layout as soon as visibility of view is changed: https://i.stack.imgur.com/WH9dn.gif

Is there any way this unexpected behavior can be fixed?

Suyash Bhatt
  • 38
  • 1
  • 7

2 Answers2

1

Check that you aren't in fullscreen mode or have translucentStatus set to true in your theme, which flags the fullscreen mode. This renders the adjustResize feature non-functional.

RESTfulGeoffrey
  • 378
  • 4
  • 8
0

I also faced same issue and didn't found any solution, if its urgent then temporary you can apply this.

Resize your layout programatically using this whenever you will change visibility of your view.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

Hope this help you.

Nilam Vaddoriya
  • 433
  • 2
  • 10
  • I will give it a try – Suyash Bhatt Sep 22 '17 at 04:20
  • I gave it a try and it acts funky. first time when visibility is changed it breaks the layout and it comes back to normal layout when more text is added. I added your suggestion after `mNextButton.setVisibility(View.VISIBLE);` and `mNextButton.setVisibility(View.GONE);` on my Fragmant.java – Suyash Bhatt Sep 22 '17 at 04:32