Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Layout: Button gets moved when Keyboard pops up

My Layout gets changed when the keyboard pops up. Specifically, the register Button gets moved upwards and rests on top of one of the EditTexts. I want my view to stay the same size and be able to scroll it in the smaller viewport when my keyboard is open. I've tried android:windowSoftInputMode="adjustResize" (Button gets moved) and "adjustPan" (Button doesn not get moved, but to see the Button, you first have to close the keyboard)

I have following xml-file:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff">
    <LinearLayout 
        android:id="@+id/register_header"
        android:orientation="horizontal"
        android:gravity="center_vertical"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:padding="@dimen/activity_vertical_margin">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ... />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
           ... />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/register_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/register_header"
        android:padding="@dimen/activity_vertical_margin"
        android:orientation="vertical" >

        // Bunch of EditText's here


    </LinearLayout>
    <LinearLayout
        android:id="@+id/register_footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center_vertical|bottom"
        android:orientation="vertical"
        android:padding="@dimen/activity_vertical_margin">

        <Button 
            android:padding="16dp"
            android:id="@+id/register_button_register"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/register" />

    </LinearLayout>

</RelativeLayout>

like image 756
Cuddl3s Avatar asked May 13 '26 23:05

Cuddl3s


2 Answers

put this in your manifest under "the" activity tag

 android:windowSoftInputMode="adjustNothing"

for more info keyboard

Instead of a RelativeLayout as the child of the ScrollView, use a LinearLayout like this

<ScrollView>
     <LinearLayout orientation="vertical">
       <LinearLayout orientation="vertical">
         <EditTexts />
       </LinearLayout>
       <Button />
    </LinearLayout>
<ScrollView>

When you have a RelativeLayout and a child with alignParentBottom=true, that child will always be at the bottom of the screen which in the adjustResize case means above the keyboard and over the EditTexts.

like image 26
browep Avatar answered May 16 '26 13:05

browep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!