Display Buttons above the keyboard

I made a registration form in which I have two buttons. Now I want that when the keyboard is displayed, the two buttons that are at the bottom should be displayed above the keyboard and not hidden under the keyboard. of this code I wrote was giving me no success.

Xml Code

<LinearLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">


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


                <EditText
                    android:inputType="textPersonName"
                    style="@style/EditText"
                    android:hint="@string/firstname"
                    android:id="@+id/et_first_name" />


                <EditText
                    android:inputType="textPersonName"
                    style="@style/EditText"
                    android:hint="@string/lastname"
                    android:id="@+id/et_last_name" />

                <Button
                    style="@style/EditText"
                    android:text="@string/country"
                    android:id="@+id/bt_country" />


                <Button
                    style="@style/EditText"
                    android:text="@string/gender"
                    android:id="@+id/bt_gender" />

                <EditText
                    style="@style/EditText"
                    android:inputType="phone"
                    android:hint="@string/mobileno"
                    android:id="@+id/et_mobile_no" />

                <EditText
                    style="@style/EditText"
                    android:inputType="textEmailAddress"
                    android:hint="@string/email"
                    android:id="@+id/et_email" />


            </LinearLayout>


        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <Button
            style="@style/EditText"
            android:id="@+id/bt_reg_cancel"
            android:text="@string/cancel"
            android:layout_gravity="bottom"
            android:layout_weight="1" />

        <Button
            style="@style/EditText"
            android:text="@string/save"
            android:id="@+id/bt_reg_save"
            android:layout_gravity="bottom"
            android:layout_weight="1" />
    </LinearLayout>


</LinearLayout>

      

Please, help

+3


source to share


2 answers


In your Android manifest, specify the property android:windowSoftInputMode="adjustResize"

. This will resize your layout when the keyboard is displayed.

So if something is at the bottom, it will show above the keyboard when it shows

"Please can you show me the code with relative linking, would it be very helpful ??? - user3917131 7 minutes ago"

Decision: -



  • ) Or put the bottom layout in the scroll itself. Then even if the keyboard is shown, you can scroll it.

2.) Weight approach: - ScrollView -> 0.7 RelativeLayout -> 0.3 -> In it write your bottom layout and give the align property to the parent bottom true. In this approach, your scrollview will only take up 0.7 screens according to the weight instructions and the rest according to your bottom position.

3.) remove the scrollview, make it linearlayout instead. Create a relative layout of the original parent and give the property to align parent bottom true with your bottom layout and layout above the linearLayout property

+1


source


You have to set leyout_weight from ScrollView to 1 for example. And set the leyout_height LinearLayout to "wrap_content". And it would be nice to set the layout_height of the ScrollView to 0dp so the LinearLayout can control its course.

<LinearLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical">

    <ScrollView
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp">
    </ScrollView>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <Button
            style="@style/EditText"
            android:id="@+id/bt_reg_cancel"
            android:text="@string/cancel"
            android:layout_gravity="bottom"
            android:layout_weight="1" />
        <Button
            style="@style/EditText"
            android:text="@string/save"
            android:id="@+id/bt_reg_save"
            android:layout_gravity="bottom"
            android:layout_weight="1" />
    </LinearLayout>


</LinearLayout>

      



This should do the trick.

0


source







All Articles