Reputation: 31283
What I have is a photo uploading activity with the photo as the main background and an edittext and a set of buttons on the bottom. When I click on the edittext, I want the soft keyboard to push the edittext and buttons up (so they are still viewable) and keep the background image the same. However, right now it only pushes it up enough to see the first line of the edittext and all my buttons are hidden.
I basically want to somehow attach a view to the softkeyboard and leave the rest of the activity alone. I've tried setting the windowSoftInputMode flag in the manifest but none of the options produce the effect I want (I don't want the layout resized and pan appears to have no affect). How do I achieve something like this?
Upvotes: 2
Views: 2120
Reputation: 63293
Unfortunately in the current SDK we are a bit at the system's mercy when it comes to how the view behaves when a soft keyboard shows up and goes away. The best way to achieve the behavior you are looking for is to leave the default input mode on the window and make sure you have one scrollable element in your view. Keep in mind, this element does not need to scroll while the keyboard is hidden (content smaller than the scroll view), but when the keyboard shows up, it will collapse the size of the scrollable view and leave everything else alone.
Here's an example. Let's say this is your res/layout/main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/control"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A Button"/>
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/control">
</ScrollView>
</RelativeLayout>
Try this as the root layout of a basic Activity and you will see that the entire LinearLayout
slides up and down with the keyboard, because Android is resizing the viewport of the ScrollView
instead of sliding up the view JUST enough to show the focused input element (which you are seeing now).
Upvotes: 1