EditText on focus scroll up without resize other views

1.2k views Asked by At

I'm trying to get an EditText field to scroll over my cameraPreview when selected. However it is now resizing the cameraPreview. I would be content with a adjustPan behaviour however I want the actionBar to stay on screen. I suspect it could be done with a scrollView however uptill no I can't prevent the cameraPreview from resizing.

<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="fill_parent"
tools:context=".MainActivity" >
    <FrameLayout
    android:id="@+id/cameraPreview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent" >

    </FrameLayout>

<!-- Fix for black overlay on menu -->
<FrameLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@android:color/transparent" >
</FrameLayout>
<ScrollView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:isScrollContainer="true"
        >
      <EditText
        android:id="@+id/inputCode"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/White"
        android:ems="10"
        android:inputType="textNoSuggestions"
        android:maxLines="1"
        android:textColor="@color/Green"
        android:textSize="32sp"
        android:layout_alignParentBottom="true" >

    </EditText>
 </ScrollView>

deformed apple

3

There are 3 answers

0
TomDoes On BEST ANSWER

Finally decided to scroll the whole view including the action bar

0
TheOne_su On

I have been searching for the solution for a long time ,finally I got it;

It's simple,

First, use scroll_view as your View which has a edit_text child;

Second, use a Relative_Layout(Linear_Layout is useless) as the child of your Scroll_View

Then,you can see it works notes: (1)Do not use layout_align_Parent_Bottom ,user layout_below instead (2)You have no need to specify window_Soft_Input_Model,the default is OK;

here is the example

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootlinearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="500dp"
    android:text="@string/hello_world" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="64dp"
            android:text="Button1" />

        <Button
            android:id="@+id/button6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button6" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button2" />

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button3" />

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button4" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/scrollView1"
            android:ems="10" >
        </EditText>

        <Button
            android:id="@+id/button8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button8" />

        <Button
            android:id="@+id/button9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button9" />

        <Button
            android:id="@+id/button10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button10" />

        <Button
            android:id="@+id/button5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button5" />
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/captionbottomrelativelayout"
    android:layout_width="320dp"
    android:layout_height="44dp"
    android:layout_below="@+id/scrollView1"
    android:orientation="horizontal" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:text="Button" />`enter code here`
</LinearLayout>

`enter code here

0
Raghava Manchala On
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan"

add the above line in your manifest activity.