Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force move Layout up, when keyboard is shown in FRAGMENT

Tags:

android

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>
like image 909
Igor Fridman Avatar asked Sep 29 '16 10:09

Igor Fridman


People also ask

How do I scroll up layout when clicking on Edittext?

than change layout design. or if it's possible for you than try this android:layout_height="match_parent" to RelativeLayout and give it a fix id also. maybe it's work for you.

How to Handle keyboard in Android studio?

To handle an individual key press, implement onKeyDown() or onKeyUp() as appropriate. Usually, you should use onKeyUp() if you want to be sure that you receive only one event. If the user presses and holds the button, then onKeyDown() is called multiple times.


1 Answers

For Fragments:

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

For Activities:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
like image 142
Swami Anil Saraswati Avatar answered Sep 27 '22 20:09

Swami Anil Saraswati