Igor Fridman
Igor Fridman

Reputation: 1297

Force move Layout up, when keyboard is shown in FRAGMENT

I have an **EditText** inside a **Fragment**. The Layout stay with no changes, when the keyboard is shown. I tried all the options below, nothing is working. I read all the topics in stackoverflow and fund nothing. If anyone have any other ideas, please share.

The options i tried:

<activity android:windowSoftInputMode="adjustPan"> </activity>

<activity android:windowSoftInputMode="adjustPan|adjustResize">

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);


android:windowSoftInputMode="stateVisible|adjustResize"

Here is my XML of the Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layoutDirection="rtl"
    tools:background="@mipmap/bg">


    <RelativeLayout
        android:id="@+id/contactUsSaperator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp">

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_toLeftOf="@+id/gcontactUsHeader"
            android:background="#ffffff" />

        <TextView
            android:id="@+id/gcontactUsHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:text="@string/contactUs"
            android:textColor="#ffffff" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_toRightOf="@+id/gcontactUsHeader"
            android:background="#ffffff" />


    </RelativeLayout>


    <LinearLayout
        android:id="@+id/contactUsOpenHour"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_below="@id/contactUsSaperator"
        android:layout_marginTop="17dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/contactUsOpenHourText"
            android:textColor="@color/blueTextColor"
            android:textStyle="bold"
            android:textSize="16dp"
            android:layout_marginRight="10dp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/contactUsOpenHourTuesdayWednesday"
            android:textColor="@color/blueTextColor"
            android:textSize="15dp"
            android:layout_marginRight="10dp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/contactUsOpenHourThursday"
            android:textColor="@color/blueTextColor"
            android:textSize="15dp"
            android:layout_marginRight="10dp"
            />
        <TextView

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/contactUsOpenHourFriday"
            android:textColor="@color/blueTextColor"
            android:textSize="15dp"
            android:layout_marginRight="10dp"
            />  

        <TextView            
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="35dp"
            android:text="@string/contactUsOpenHourPhone"
            android:textColor="@color/blueTextColor"
            android:textStyle="bold"
            android:textSize="16dp"
            android:layout_marginRight="10dp"
            />

        <FrameLayout
            android:layout_marginTop="25dp"
            android:layout_width="wrap_content"
            android:layout_height="150dp">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="150dp"
                android:background="@mipmap/contact_us_tex_fild"
                android:scaleType="fitXY"
                />
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="3dp"
                >
                <EditText
                    android:id="@+id/contactUsEditText"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:hint="@string/contactHint"
                    android:textSize="15dp"

                    android:textColor="@color/blueTextColor"
                    android:textColorHint="@color/blueTextColor"
                    android:inputType="text"
                    />

            </ScrollView>

        </FrameLayout>

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            >
            <ImageView
                android:id="@+id/contactUsSendButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/button"
                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/contacUsSendButton"
                android:layout_gravity="center"
                android:textColor="@color/blueTextColor"
                android:textSize="22dp"
                android:textStyle="bold"
                />

        </FrameLayout>

    </LinearLayout>

</LinearLayout>

Upvotes: 6

Views: 7399

Answers (2)

satyan_android
satyan_android

Reputation: 364

Take scrollView inside linear Layout or replace Your LinearLayout with scrollview

Upvotes: 2

Swami Anil Saraswati
Swami Anil Saraswati

Reputation: 124

For Fragments:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

For Activities:

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

Upvotes: 8

Related Questions