Search code examples
androidandroid-scrollviewandroid-constraintlayout

Adding constraint in ConstraintLayout wrapped in ScrollView cuts off bottom


I wrapped the ConstraintLayout inside ScrollView. However, something cuts off the last widget if I add the constraint and without constraint, it will scroll down without cutting off.

The following picture is with the constraint. All widgets are connected to the top in the same manner. It doesn't matter how big the distance is. enter image description here

Here is the picture without the constraint. enter image description here

I have tried margins and paddings. With added padding, it just created white space above the bottom toolbar. I have also tried to restart the AndroidStudio and Invalidate Caches/Restart. Without success so far.

Here's the code

<?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"
    tools:context="com.example.boss.abeacon.DataAcquisitionActivity">

    <android.support.constraint.ConstraintLayout 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="wrap_content"
        tools:context="com.example.boss.abeacon.DataAcquisitionActivity">

        <EditText
            android:id="@+id/yCoordinate_editor"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:digits="0123456789"
            android:ems="10"
            android:imeOptions="actionDone"
            android:inputType="numberSigned"
            android:textSize="12sp"
            app:layout_constraintStart_toStartOf="@+id/position_id_editor"
            app:layout_constraintTop_toBottomOf="@+id/xCoordinate_editor" />

        <EditText
            android:id="@+id/xCoordinate_editor"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:digits="0123456789"
            android:ems="10"
            android:imeOptions="actionDone"
            android:inputType="numberSigned"
            android:textSize="12sp"
            app:layout_constraintStart_toStartOf="@+id/position_id_editor"
            app:layout_constraintTop_toBottomOf="@+id/position_id_editor" />

        <TextView
            android:id="@+id/label_number_of_data_editor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:text="Number of data \nin a position"
            app:layout_constraintBottom_toBottomOf="@+id/number_of_data_editor"
            app:layout_constraintEnd_toStartOf="@+id/number_of_data_editor" />

        <EditText
            android:id="@+id/inliers_window_editor"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:digits="1234567890"
            android:ems="10"
            android:hint="#"
            android:imeOptions="actionDone"
            android:inputType="number"
            android:textSize="12sp"
            app:layout_constraintStart_toStartOf="@+id/room_name_editor"
            app:layout_constraintTop_toBottomOf="@+id/number_of_data_editor" />

        <TextView
            android:id="@+id/label_inliers_window_editor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:text="Inliers' window size"
            app:layout_constraintBottom_toBottomOf="@+id/inliers_window_editor"
            app:layout_constraintEnd_toStartOf="@+id/inliers_window_editor" />

        <TextView
            android:id="@+id/label_minor_bracon_editor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:text="Minor values \nof beacons"
            app:layout_constraintBottom_toBottomOf="@+id/minor_beacon_editor"
            app:layout_constraintEnd_toStartOf="@+id/minor_beacon_editor" />

        <EditText
            android:id="@+id/number_of_data_editor"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:digits="1234567890"
            android:ems="10"
            android:hint="#"
            android:imeOptions="actionNext"
            android:inputType="number"
            android:textSize="12sp"
            app:layout_constraintStart_toStartOf="@+id/room_name_editor"
            app:layout_constraintTop_toBottomOf="@+id/minor_beacon_editor" />

        <EditText
            android:id="@+id/minor_beacon_editor"
            android:layout_width="150dp"
            android:layout_height="0dp"
            android:layout_marginTop="16dp"
            android:digits="1234567890 "
            android:ems="10"
            android:hint="1 2 3 10 21"
            android:imeOptions="actionNext"
            android:inputType="number"
            android:textSize="12sp"
            app:layout_constraintStart_toStartOf="@+id/room_name_editor"
            app:layout_constraintTop_toBottomOf="@+id/room_name_editor" />

        <TextView
            android:id="@+id/label_position_id_editor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:text="Position ID"
            app:layout_constraintBottom_toBottomOf="@+id/position_id_editor"
            app:layout_constraintEnd_toStartOf="@+id/position_id_editor" />

        <EditText
            android:id="@+id/position_id_editor"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:digits="0123456789"
            android:ems="10"
            android:imeOptions="actionDone"
            android:inputType="number"
            android:textSize="12sp"
            app:layout_constraintStart_toStartOf="@+id/room_name_editor"
            app:layout_constraintTop_toBottomOf="@+id/auto_position_id_checkBox" />

        <TextView
            android:id="@+id/label_room_name_editor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:text="Room name"
            app:layout_constraintBottom_toBottomOf="@+id/room_name_editor"
            app:layout_constraintEnd_toStartOf="@+id/room_name_editor" />

        <EditText
            android:id="@+id/room_name_editor"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="150dp"
            android:layout_marginTop="32dp"
            android:ems="10"
            android:hint="Enter file name"
            android:inputType="textPersonName"
            android:textSize="12sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:id="@+id/scan_btn"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="32dp"
            android:layout_marginStart="32dp"
            android:text="Start"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            tools:layout_editor_absoluteY="515dp" />

        <TextView
            android:id="@+id/kazoeru"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:layout_marginStart="32dp"
            android:text="#"
            app:layout_constraintBottom_toTopOf="@+id/scan_btn"
            app:layout_constraintStart_toStartOf="parent" />

        <CheckBox
            android:id="@+id/auto_position_id_checkBox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="32dp"
            android:text="Auto position ID"
            android:textSize="12sp"
            app:layout_constraintStart_toStartOf="@+id/position_id_editor"
            app:layout_constraintTop_toBottomOf="@+id/setParameters_btn" />

        <TextView
            android:id="@+id/last_position_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginStart="8dp"
            android:textSize="12sp"
            app:layout_constraintBottom_toBottomOf="@+id/position_id_editor"
            app:layout_constraintStart_toEndOf="@+id/position_id_editor" />

        <TextView
            android:id="@+id/label_xCoordinate_editor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:text="X"
            app:layout_constraintBottom_toBottomOf="@+id/xCoordinate_editor"
            app:layout_constraintEnd_toStartOf="@+id/xCoordinate_editor" />

        <TextView
            android:id="@+id/label_yCoordinate_editor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:text="Y"
            app:layout_constraintBottom_toBottomOf="@+id/yCoordinate_editor"
            app:layout_constraintEnd_toStartOf="@+id/yCoordinate_editor" />

        <TextView
            android:id="@+id/last_xCoordinate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginStart="8dp"
            app:layout_constraintBottom_toBottomOf="@+id/xCoordinate_editor"
            app:layout_constraintStart_toEndOf="@+id/xCoordinate_editor" />

        <TextView
            android:id="@+id/last_yCoordinate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginStart="8dp"
            app:layout_constraintBottom_toBottomOf="@+id/yCoordinate_editor"
            app:layout_constraintStart_toEndOf="@+id/yCoordinate_editor" />

        <Button
            android:id="@+id/setParameters_btn"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="32dp"
            android:layout_marginStart="32dp"
            android:layout_marginTop="8dp"
            android:onClick="setParametersButtonOnClick"
            android:text="Set parameters"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/inliers_window_editor" />
    </android.support.constraint.ConstraintLayout>
</ScrollView>

I am running Ubuntu 16.04.LTS and the latest version of the AndroidStudio.


Solution

  • Update The layout works in the latest beta release. Upgrading to 1.1.0-beta3 will resolve the problem.


    Regarding the differences in the designer layout, take a look at the XML for scan_btn. Without a top constraint, the designer imposes a position on it which is 515dp from the top. This is there just to keep things in place before all the constraints can be laid in.

    tools:layout_editor_absoluteY="515dp"
    

    When you constrain the top with 32dp, the above designer position is not used and 32dp from the upper widget is used instead. This will account for the difference in position with and without the top constraint. You have to constrain the top or the widget will float to the top since designer constraints do not work except in the designer, so choose a top constraint and a top margin that works for you.