Kabir Raz Kabir Raz - 3 months ago 22
Android Question

Android- Content of forms not adjusting when keyboard opens

I have a form which has few edit text and below all there is button like this
This is a form on fragment
Its looks fine until i open keyboard the form doesn't resize itself even after applying different property like

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN |WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE |WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE |WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN );
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_MODE_CHANGED);


Also i tried in manifest and in fragment layout but most of it i can achieve this
The buttons Comes Up Not EditText

Here is my Fragment Layout where is EditTexts

<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"

>

<android.support.design.widget.TextInputLayout

android:layout_height="wrap_content"
android:layout_width="185dp"
android:id="@+id/view"
android:layout_below="@+id/Uploader"
android:layout_alignLeft="@+id/view4"
android:layout_alignStart="@+id/view4"
android:fitsSystemWindows="true"
android:layout_marginTop="58dp">

<EditText
android:layout_width="175dp"
android:layout_height="wrap_content"
android:id="@+id/first_Name"
android:drawableLeft="@drawable/ic_perm_identity_black_24dp"

android:inputType="textPersonName"
android:textColor="#000"
android:hint="First Name"
android:layout_alignTop="@+id/last_Name" />

</android.support.design.widget.TextInputLayout>


<android.support.design.widget.TextInputLayout
android:layout_width="185dp"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:layout_alignTop="@+id/view"
android:layout_toRightOf="@+id/view"
android:layout_toEndOf="@+id/view"
android:id="@+id/view2">
<EditText
android:layout_width="175dp"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_perm_identity_black_24dp"
android:id="@+id/last_Name"
android:inputType="textPersonName"
android:hint="Last Name" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:layout_below="@+id/view2"
android:layout_alignRight="@+id/view2"
android:layout_alignEnd="@+id/view2"
android:id="@+id/view3">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/phone"
android:inputType="phone"
android:hint="Enter Phone Number"
android:drawableLeft="@drawable/ic_call_black_24dp"
/>

</android.support.design.widget.TextInputLayout>


<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:layout_below="@+id/view3"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/view4">
<EditText
android:layout_width="match_parent"

android:layout_height="wrap_content"
android:id="@+id/mailID"
android:drawableLeft="@drawable/ic_email_black_24dp"
android:inputType="textEmailAddress"
android:hint="Enter Email Address"
/>
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:layout_below="@+id/view4"
android:layout_alignRight="@+id/view2"
android:layout_alignEnd="@+id/view2"
android:id="@+id/view6">

<EditText
android:layout_width="match_parent"

android:layout_height="wrap_content"
android:id="@+id/password"
android:drawableLeft="@drawable/ic_lock_black_24dp"
android:inputType="textVisiblePassword"
android:hint="Enter Password"


/>
</android.support.design.widget.TextInputLayout>



<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fitsSystemWindows="false"
android:id="@+id/Submit"
android:text="SUBMIT"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="74dp" />


<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="@drawable/ic_add_a_photo_black_48dp"
android:id="@+id/Uploader"


android:layout_marginTop="84dp"

android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/Image_Preview"
android:layout_toLeftOf="@+id/Uploader"
android:layout_toStartOf="@+id/Uploader"
android:layout_alignBottom="@+id/Uploader" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign In"
android:textSize="25dp"
android:id="@+id/regUser"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/view3"
android:layout_alignEnd="@+id/view3" />



</RelativeLayout>
</ScrollView>


My layout is not adjusting even after trying
android:windowSoftInputMode="adjustPan|adjustResize"
in layout file and also in manifest

Answer

The "Submit" button has android:layout_alignParentBottom="true" which is what makes it appear just above the keyboard. You need to change this to an appropriate layout_* param which places it where you actually want it. In fact, you should consider using a LinearLayout or TableLayout in order to keep the child views where you want them.

Comments