1

I have a screen with a title, 5 TextViews, 5 Spinners, and 2 buttons at the bottom which causes the 5th set of TextView/Spinner to go off-screen towards the bottom. I have searched about having a ScrollView within a ConstraintLayout and have tried the various things ive found with setting the certain height and width to "0dp" and adding the constraint to the ScrollView itself but still the only thing that happens is the 5 sets appear but still are not scrollable. I saw a question similar to this but they have nothing at the bottom so they constraint to the bottom of parent. I need to constraint to the top of my buttons at the bottom so my buttons stay in place and only the middle scrolls but when i set my bottom constraint to the top of buttons the entire view disappears.

This is my current XML

<?xml version="1.0" encoding="utf-8"?>
   <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="match_parent"
tools:context="teamtriplej.com.lipidlator21.CardiolipinsActivity">

<Button
    android:id="@+id/btnSubmit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="30dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="16dp"
    android:background="@android:color/black"
    android:text="@string/Submit"
    android:textColor="@android:color/white"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.761"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent" />

<Button
    android:id="@+id/btnBack"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="30dp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="8dp"
    android:background="@android:color/black"
    android:text="@string/Back"
    android:textColor="@android:color/white"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.216"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent" />

<TextView
    android:id="@+id/tvTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="35dp"
    android:text="@string/CLConfiguration"
    android:textAlignment="center"
    android:textColor="@android:color/black"
    android:textSize="24sp"
    android:textStyle="bold"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    app:layout_constraintHorizontal_bias="0.504" />
<ScrollView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@id/tvTitle">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
<TextView
    android:id="@+id/tvIon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="30dp"
    android:text="@string/Ion"
    android:textColor="@android:color/black"
    android:textSize="18sp"
    android:textStyle="bold"
    app:layout_constraintLeft_toLeftOf="parent"
    android:layout_marginStart="8dp" />

<Spinner
    android:id="@+id/spnIon"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="25dp"
    android:layout_marginRight="25dp"
    android:layout_marginTop="12dp"
    android:entries="@array/ion_array"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tvIon"
    android:layout_marginStart="25dp"
    android:layout_marginEnd="25dp" />

<TextView
    android:id="@+id/tvAcylChain"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="30dp"
    android:text="@string/sn1_1"
    android:textColor="@android:color/black"
    android:textSize="18sp"
    android:textStyle="bold"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/spnIon"
    android:layout_marginStart="8dp" />

<Spinner
    android:id="@+id/spnSn1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="25dp"
    android:layout_marginRight="25dp"
    android:layout_marginTop="12dp"
    android:entries="@array/sn_array"
    android:textColor="@android:color/black"
    android:textSize="18sp"
    android:textStyle="bold"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tvAcylChain"
    android:layout_marginStart="25dp"
    android:layout_marginEnd="25dp" />

<TextView
    android:id="@+id/tvSn1_3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="30dp"
    android:text="@string/sn1_3"
    android:textColor="@android:color/black"
    android:textSize="18sp"
    android:textStyle="bold"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/spnSn1"
    android:layout_marginStart="8dp" />

<Spinner
    android:id="@+id/spnSn1_3"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="25dp"
    android:layout_marginLeft="25dp"
    android:layout_marginRight="25dp"
    android:layout_marginStart="25dp"
    android:layout_marginTop="12dp"
    android:entries="@array/ratios_array"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tvSn1_3" />

<TextView
    android:id="@+id/tvSn2_1_Result"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="30dp"
    android:text="@string/sn2_1"
    android:textColor="@android:color/black"
    android:textSize="18sp"
    android:textStyle="bold"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/spnSn1_3"
    android:layout_marginStart="8dp" />

<Spinner
    android:id="@+id/spnSn2_1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="25dp"
    android:layout_marginLeft="25dp"
    android:layout_marginRight="25dp"
    android:layout_marginStart="25dp"
    android:layout_marginTop="12dp"
    android:entries="@array/ratios_array"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tvSn2_1_Result" />

<TextView
    android:id="@+id/tvSn2_3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/sn2_3"
    android:textColor="@android:color/black"
    android:textSize="18sp"
    android:textStyle="bold"
    android:layout_marginTop="30dp"
    app:layout_constraintTop_toBottomOf="@+id/spnSn2_1"
    android:layout_marginLeft="8dp"
    app:layout_constraintLeft_toLeftOf="parent"
    android:layout_marginStart="8dp" />

<Spinner
    android:id="@+id/spnSn2_3"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="25dp"
    android:layout_marginRight="25dp"
    android:layout_marginTop="8dp"
    android:entries="@array/ratios_array"
    android:textColor="@android:color/black"
    android:textSize="18sp"
    android:textStyle="bold"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tvSn2_3" />

    </android.support.constraint.ConstraintLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
6
  • Because a screen can lay down all View,you can set one of View 's android:layout_height="500dp" .You will scroll in the screen. Commented Oct 30, 2017 at 1:23
  • So i should set the android:layout_height="500dp" inside the Scrollview instead of the wrap_content? Commented Oct 30, 2017 at 1:36
  • You could set the height of TextView or Spinner inside ConstraintLayout .And it will scroll.I try it in my code .And it worked . Commented Oct 30, 2017 at 1:39
  • Ok perfect I simply made all my spinners a little bit taller and it works but now I have a new issue... the scrollview still does not stop before reaching the buttons at the bottom... it scrolls behind the buttons Commented Oct 30, 2017 at 1:48
  • You want to ScrollView above the Button(submit) and Button(back) . Commented Oct 30, 2017 at 1:54

1 Answer 1

5

Use this in your ScrolView

Add android:layout_height="0dp" and app:layout_constraintBottom_toTopOf="@id/btnBack"

  <ScrollView
    android:layout_width="0dp"
    android:id="@+id/scroll_view"
    android:layout_height="0dp"
    app:layout_constraintBottom_toTopOf="@+id/btnBack"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tvTitle">
Sign up to request clarification or add additional context in comments.

4 Comments

I tried exactly what you have above and now the scroll view goes behind the title and still is behind the buttons... i just checked to make sure im using proper id's for buttons and title and they are correct
You can check again.@JoseMoreno
Yes of course...i think i just realized what you were trying to do.... i think i need to do the margin + the height of the title and the margin + height of the button to make cover all the margin
Beautiful! Thank you very much! Sorry i cant upvote, not enough rep but as soon as I do i will return to this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.