androidandroid-studioandroid-layoutandroid-scrollview

how di add a ScrollView that scrolls behind a relative layout


I've got a parent RelativeLayout that holds a ScrollView on the top half of my screen and another RelativeLayout on the bottom half. Currently where they meet its a bit cluttered on smaller devices like the samsung A5. How can I get my ScrollView to not overlap with the RelativeLayout? Also how can I make the RelativeLayout disappear when the keyboard is open?

Virual Device with SamsungA5 screen specs

Below is my layout.xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".ui.ConfigActivity">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@layout/config_panel">

        <RelativeLayout
            android:id="@+id/form_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <TextView
                android:id="@+id/textLabelConfig"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="5dp"
                android:text="Serial Setup:"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/labelSerialBaud"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/textLabelConfig"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:text="Baud Rate:" />

            <EditText
                android:id="@+id/editSerialBaud"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@id/textLabelConfig"
                android:layout_marginLeft="125dp"
                android:layout_marginTop="10dp"
                android:ems="10"
                android:inputType="textNoSuggestions"
                android:text="9600" />

            <TextView
                android:id="@+id/labelSerialBits"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSerialBaud"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:text="Bit setup:" />

            <EditText
                android:id="@+id/editSerialBits"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSerialBaud"
                android:layout_marginLeft="125dp"
                android:layout_marginTop="10dp"
                android:ems="10"
                android:inputType="textNoSuggestions"
                android:text="8n1" />


            <CheckBox
                android:id="@+id/checkBox485"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSerialBits"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                android:text="RS485" />

            <CheckBox
                android:id="@+id/checkBox232"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSerialBits"
                android:layout_marginLeft="100dp"
                android:layout_marginTop="10dp"
                android:text="RS232" />


            <TextView
                android:id="@+id/textLabelGSM"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/checkBox485"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="5dp"
                android:text="GSM Setup:"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/labelSim1APN"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/textLabelGSM"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:text="SIM1 APN:"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/editSim1APN"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@id/textLabelGSM"
                android:layout_marginLeft="125dp"
                android:layout_marginTop="5dp"
                android:ems="10"
                android:inputType="textNoSuggestions"
                android:text="" />

            <TextView
                android:id="@+id/labelSim1User"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSim1APN"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:text="APN Username:" />

            <EditText
                android:id="@+id/editSim1User"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSim1APN"
                android:layout_marginLeft="125dp"
                android:layout_marginTop="5dp"
                android:ems="10"
                android:inputType="textNoSuggestions"
                android:text="" />

            <TextView
                android:id="@+id/labelSim1Passwd"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSim1User"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:text="APN Password:" />

            <EditText
                android:id="@+id/editSim1Passwd"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSim1User"
                android:layout_marginLeft="125dp"
                android:layout_marginTop="10dp"
                android:ems="10"
                android:inputType="textNoSuggestions"
                android:text="" />

            <!--- Sim 2 -->

            <TextView
                android:id="@+id/labelSim2APN"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSim1Passwd"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="30dp"
                android:text="SIM2 APN:"
                android:textStyle="bold" />

            <EditText
                android:id="@+id/editSim2APN"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSim1Passwd"
                android:layout_marginLeft="125dp"
                android:layout_marginTop="15dp"
                android:ems="10"
                android:inputType="textNoSuggestions"
                android:text="" />

            <TextView
                android:id="@+id/labelSim2User"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSim2APN"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:text="APN Username:" />

            <EditText
                android:id="@+id/editSim2User"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSim2APN"
                android:layout_marginLeft="125dp"
                android:layout_marginTop="5dp"
                android:ems="10"
                android:inputType="textNoSuggestions"
                android:text="" />

            <TextView
                android:id="@+id/labelSim2Passwd"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSim2User"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="20dp"
                android:text="APN Password:" />

            <EditText
                android:id="@+id/editSim2Passwd"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_below="@id/labelSim2User"
                android:layout_marginLeft="125dp"
                android:layout_marginTop="5dp"
                android:ems="10"
                android:inputType="textNoSuggestions"
                android:text="" />
        </RelativeLayout>
    </ScrollView>
    <RelativeLayout
        android:id="@+id/lower_layout"
        android:layout_width="match_parent"
        android:layout_height="155dp"
        android:alpha="1.0"
        android:layout_alignParentBottom="true">

        <include layout="@layout/config_panel" />

        <Button
            android:id="@+id/buttonAdvConfig"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:layout_marginRight="10dp"
            android:layout_marginBottom="5dp"
            android:text="@string/text_advanced" />
    </RelativeLayout>
</RelativeLayout>

Solution

  • currently your ScrollView fits whole screen, android:layout_above="@layout/config_panel" is no-op, as config_panel id isn't set for any child of ScrollViews parent (it is placed deeper). you probably should align above lower_layout (this view is placed under ScrollView in XML, both have same parent)

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@layout/lower_layout">