Ambran
Ambran

Reputation: 2617

Fragments and soft keyboard layout issue

I have a fragment with a ScrollView and a Button. The ScrollView contains a LinearLayout of some TextViews and EditViews. I would like the button to remain in the bottom when soft keyboard is shown like I did with my app's activities, but it keeps rising up with the keyboard. I've read that the ScrollView may be responsible for that behavior, But without it there will be no access to the bottom EditViews.

The android:isScrollContainer="false" doesn't help either and adding android:layout_above="@+id/button_bar" to the ScrollView is not applicable in Fragments (why, I don't know). Any Ideas?

The XML layout

<FrameLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="fragment.ProfileFragment">

    <ScrollView
        android:id="@+id/scroll_profile"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="0dp"
        android:fadingEdge="none"
        android:scrollbars="none"
        android:isScrollContainer="false" >

        <RelativeLayout
            android:id="@+id/layout_profile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:orientation="vertical"
            android:padding="0dp">

            <TextView
                android:id="@+id/text_first_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="@string/first_name"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/edit_first_name"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="top"
                android:imeOptions="actionNext"
                android:lines="1"
                android:padding="5dp"
                android:inputType="text" />

            <TextView
                android:id="@+id/text_last_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="@string/last_name"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/edit_last_name"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="top"
                android:imeOptions="actionNext"
                android:lines="1"
                android:padding="5dp"
                android:inputType="text" />

            <TextView
                android:id="@+id/text_phone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="@string/phone_number"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/edit_phone"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="top"
                android:imeOptions="actionNext"
                android:lines="1"
                android:inputType="phone"
                android:padding="5dp" />

            <TextView
                android:id="@+id/text_email"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="@string/email"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/edit_email"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="top"
                android:imeOptions="actionDone"
                android:lines="1"
                android:padding="5dp"
                android:inputType="textEmailAddress" />

            <TextView
                android:id="@+id/text_help"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="@string/show_help_texts"
                android:textStyle="bold" />

            <CheckBox
                android:id="@+id/check_help"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="top"
                android:lines="1"
                android:padding="5dp" />

            <TextView
                android:id="@+id/text_code"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:layout_marginTop="20dp"
                android:text="@string/employee_code"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/edit_code"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="top"
                android:hint="@string/employee_code_hint"
                android:imeOptions="actionDone"
                android:lines="1"
                android:padding="5dp"
                android:inputType="textPassword" />
        </RelativeLayout>
    </ScrollView>

    <LinearLayout
        android:id="@+id/button_bar"
        style="?android:attr/buttonBarStyle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="@drawable/button_bar"
        android:layout_gravity="bottom"
        android:layout_marginTop="@dimen/activity_vertical_margin">

        <Button
            style="?android:attr/buttonBarButtonStyle"
            android:id="@+id/button_save"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/button_save"
            android:textColor="@android:color/primary_text_dark" />
    </LinearLayout>
</FrameLayout>

Upvotes: 0

Views: 1498

Answers (1)

Berť&#225;k
Berť&#225;k

Reputation: 7322

Did you try to use android:windowSoftInputMode="adjustPan" in your manifest, for your activity element? I think it could help.

I also reccomend to replace your FrameLayout with vertical LinearLayout, if you want to keep the button under your ScrollView.

Upvotes: 1

Related Questions