Click here to Skip to main content
15,881,561 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a some multiline EditText controls in a ScrollView. When I tap any of the EditText controls, the soft keyboard appears,
but the EditText and its cursor position appears behind the keyboard. I need to manually scroll the view to top.
Is there any way to fix this issue? In the below code cameraButton always appear above the keyboard.

XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/crlayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
<ScrollView
        android:id="@+id/scrollview"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_alignParentTop="true">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
        <ImageView
            android:id="@+id/boxImage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            />
        <EditText
            android:id="@+id/new_box_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="Title"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/new_box_descri"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Description"
            android:gravity="top"
            android:inputType="textCapSentences|textMultiLine"
            android:lines="5"
            android:windowSoftInputMode="stateAlwaysVisible" />

</LinearLayout>
    </ScrollView>
    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:background="@android:color/white"
        >
        <ImageButton
            android:id="@+id/cameraButton"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:contentDescription="Open Camera"
            app:srcCompat="@drawable/ic_box_camera_icon"
            android:background="?attr/selectableItemBackgroundBorderless"
            />
    </LinearLayout>
</RelativeLayout>


What I have tried:

I tried scrolling the scrollView to bottom on EditText Click, But this won't work as the keyboard appears after the EditText onClick, and layout resized as keyboard appears.
Posted
Updated 14-May-18 2:38am

1 solution

In Manifest file add the below code for this activity
<activity android:windowSoftInputMode="adjustPan">


If above method does not work then try this one

android:windowSoftInputMode="stateVisible|adjustResize" 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900