1

I am facing an annoying problem for a few hours.

I have a relative layout with a logo which has a marginTop and a button aligned to the bottom, which has a marginBottom. Between these two views there are also some other views, centered.

enter image description here

The problem occurs when the keyboard is opened. What I want to happen is lift everything up. What does happen is that the button is lifted, the logo stays in a fixed position, and the other views are squeezed in the middle (on small devices they even disappear).

enter image description here

I know the problem can be solved if all the other views would be relative to one another, starting from the logo or button (never both!). But in this case, the logo and the button won't be in the desired places.

Any ideas are greatly appreciated.

DenStudent
  • 906
  • 1
  • 13
  • 37
Teodora
  • 11
  • 3

1 Answers1

0

I tried what you discribe here:

do not forget the FILLVIEWPORT = true. for the scrollview

This is what I figured out and it works perfect:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <RelativeLayout
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="be.vanlooverenkoen.testing.MainActivity">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="150dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:scaleType="fitXY"
            app:srcCompat="@mipmap/ic_launcher" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/button"
            android:layout_below="@+id/imageView"
            android:background="@color/colorAccent" />

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="Button" />
    </RelativeLayout>
</ScrollView>
vanlooverenkoen
  • 2,121
  • 26
  • 50
  • Yes, it does work, but the edittext is squeezed. In my case, since I have android:layout_marginTop="50dp" for logo and android:layout_marginBottom="100dp" for button the size of the edit text is even smaller (sometimes even gone). – Teodora Jan 05 '17 at 13:49