2

This is my layout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/defaut_padding" >

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/defaut_padding"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@+id/photo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/picture"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="fitXY" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_margin="10dp"
                android:background="@drawable/watermark" />

            <ProgressBar
                android:id="@+id/bitmap_loading"
                style="?android:attr/progressBarStyleLarge"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:visibility="visible" />
        </FrameLayout>

        <FrameLayout
            android:id="@+id/user"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/photo"
            android:layout_marginLeft="15dp"
            android:layout_marginTop="-30dp"
            android:background="@android:color/white"
            android:padding="@dimen/smallest_padding" >

            <ImageView
                android:id="@+id/user_picture"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:src="@drawable/anonymous_user" />
        </FrameLayout>

        <TextView
            android:id="@+id/user_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/user"
            android:layout_marginLeft="@dimen/defaut_padding"
            android:layout_toRightOf="@id/user"
            android:text="@string/anonymous_user"
            android:textStyle="bold" />
    </RelativeLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
<EditText
    android:id="@+id/input_description"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="top"
    android:padding="5dp"
    android:layout_marginBottom="@dimen/defaut_padding"
    android:background="@drawable/textfield"
    android:hint="@string/description_hint"
    android:focusableInTouchMode="true"
    android:maxLines="3"
    android:scrollbars="vertical" />

<Button
    android:id="@+id/publish"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/confirm_button_selector"
    android:text="@string/confirm_button"
    android:textColor="@android:color/white"
    android:textSize="@dimen/big_text_size"
    android:textStyle="bold" />

    </FrameLayout>
</LinearLayout>

</ScrollView>

I want to scroll it when the soft keyboard appears when I start to digit at the EditText. How can I do this? Currenty the scroll works, but the keyboard appears above the button, and I want the button above the keyboard

I've tried to move the scrool when the user clicks in the EditText, doing something like this:

mSv.scrollTo(0, mSv.getBottom());

where mSv is my ScrollView

But it only works when the user clicks in the EditText at the second time.

Thank you for any help.

androidevil
  • 9,011
  • 14
  • 41
  • 79
  • 1
    Try this customview as a parent group element in your layout http://stackoverflow.com/questions/7300497/adjust-layout-when-soft-keyboard-is-on – Pragnani Mar 20 '13 at 19:11
  • Thank you. I've use this custom layout, and put the mSv.scrollTo(0, mSv.getBottom()); when the keyboard is show, but the layout it is not moved yet – androidevil Mar 20 '13 at 20:41
  • See a very simple solution that works at https://stackoverflow.com/questions/15323758/android-how-to-push-button-above-soft-keyboard/67798240#67798240 – Jeffrey Jun 02 '21 at 02:51

3 Answers3

2

Try to change your Keyboard to pan instead of resize. You could do that in your AndroidManifest.xml file, for your particular Activity, add the below to it

android:windowSoftInputMode="adjustPan"

or

If you want to hide then:

EditText editTextSearch = (EditText) findViewById(R.id.editTextSearch);

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextSearch.getWindowToken(), 0);

If want to show:

EditText editTextSearch = (EditText) findViewById(R.id.editTextSearch);
editTextSearch.requestFocus();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
Sikander Bhutto
  • 226
  • 1
  • 11
0

If you use a RelativeLayout (outside of ScrollView) being aligned to the bottom, it will stick to the bottom of the available screen—above the keyboard. ScrollView then needs a bottom margin to not overlay the button.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"   
    android:layout_width="match_parent"
    android:layout_height="match_parent" >  

    <ScrollView      
        android:layout_height="match_parent"
        android:layout_width="match_parent"    
        android:orientation="vertical"      
        android:layout_marginBottom="48dp" >    

        /* Here your elements ... like EditText */

    </ScrollView>   

    <RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:orientation="vertical" 
         android:layout_marginBottom="0px"
         android:layout_alignParentBottom="true" > 

        <Button      
         android:layout_width="fill_parent"  
         android:layout_height="48dp"
         android:text="ddd" />        

    </RelativeLayout>
</RelativeLayout>

This works only if you (as far as I could evaluate)

  • have a RelativeLayout as parent
  • have a ScrollView as the only child besides the RelativeLayout containing the button OR have another View (e.g. LinearLayout) containing a ScrollView somewhere (for whatever reason)

If you don't want the button to always stick to the bottom, you need to detect if the keyboard is shown or not as explained in Pragnani's link.

Tony
  • 2,242
  • 22
  • 33
user1666456
  • 351
  • 1
  • 9
  • Thank you, but it does not works. My keyboard still appears above the button. – androidevil Mar 20 '13 at 20:41
  • Sorry. I discovered that things are little bit more complicated. Try my updated answer. It works for me. – user1666456 Mar 20 '13 at 21:14
  • Thank you again, I've already tried this, but what happens is that the button will appears over the entire layout, and what I want to do is make the entire layout (button and other views scroll) – androidevil Mar 20 '13 at 21:32
  • Do I understand correctly? You want to scroll the whole layout, this works, but the bottom part still is behind the keyboard? Then simply put your stuff into the parent `RelativeLayout` and add the `alignParentBottom` thing. – user1666456 Mar 20 '13 at 21:51
0

Check this SO answer. It should solve the problem "..that the button will appears over the entire layout, and what I want to do is make the entire layout (button and other views scroll)"

Tony
  • 2,242
  • 22
  • 33