views:

819

answers:

2

I have text area and and down to that "ok" and "cancel" button. when i click on text area keyboard appear and focus on the text area and buttons get hide behind the keyboard.

i want when text area get focus scroll a little bit and also display the bottom buttons while text area id selected.

A: 

You could try wrapping your existing layout in a ScrollView:
http://developer.android.com/intl/zh-CN/reference/android/widget/ScrollView.html
Your layout xml file might look like:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ScrollView01" android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <EditText android:text="@string/hello" android:id="@+id/EditText01" 
            android:layout_width="wrap_content" android:layout_height="wrap_content">
        </EditText>
        <LinearLayout 
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <Button android:text="@+id/Button01" android:id="@+id/Button01" 
                android:layout_width="wrap_content" android:layout_height="wrap_content">
            </Button>
            <Button android:text="@+id/Button02" android:id="@+id/Button02" 
                android:layout_width="wrap_content" android:layout_height="wrap_content">
            </Button>
        </LinearLayout>
    </LinearLayout>
</ScrollView>

Comment Response:
You might want to check out this page:
http://developer.android.com/intl/zh-CN/resources/articles/on-screen-inputs.html

I think results you want might be accomplished by moving the buttons outside of the Scrollview and setting android:windowSoftInputMode="adjustResize" on the activity.

Dan B
i am already using scrollview but when keyboard appears it do not scroll to display buttons.
Faisal khan
A: 

i fixed it by myself :D following is the code

i called the following method when textfield gain the focus

private final void focusOnButtons(){
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                ScrollView sv = (ScrollView)findViewById(R.id.scrl);
                sv.scrollTo(0, sv.getBottom());
            }
        },1000);
    }
Faisal khan