Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollview inside constraint layout does not scroll to the bottom of the parent constraint

I have a form which has around 12/13 fields. I used a Scrollview inside a constraint layout. Below is the hierarchy of the XML layout. The problem is, it doesn't scroll to the bottom instead scrolls only to the first initial 10 views. The last 3 fields gets hidden as the view does not scroll any further.

PARENT LAYOUT

<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:id="@+id/activity_register" android:layout_width="match_parent" android:layout_height="match_parent" android:focusableInTouchMode="true" android:orientation="vertical">  <!-- Textview and a button -->    <ScrollView     android:id="@+id/scrollView"     android:layout_width="0dp"     android:layout_height="wrap_content"     android:layout_marginBottom="10dp"     android:layout_marginTop="10dp"     android:orientation="vertical"     android:overScrollMode="never"     android:scrollbars="none"     app:layout_constraintLeft_toLeftOf="parent"     app:layout_constraintRight_toRightOf="parent"     app:layout_constraintTop_toBottomOf="@+id/view"     tools:layout_constraintBottom_creator="1"     tools:layout_constraintLeft_creator="1"     tools:layout_constraintRight_creator="1"     tools:layout_constraintTop_creator="1"     tools:layout_editor_absoluteX="0dp"     tools:layout_editor_absoluteY="0dp">     <android.support.constraint.ConstraintLayout         android:id="@+id/constraintLayout"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical">                  <!-- Child Views (12/13 views of the fields)-->    </android.support.constraint.ConstraintLayout>  </ScrollView>  </android.support.constraint.ConstraintLayout> 
like image 759
Maheshwari Reddy Avatar asked Feb 25 '17 07:02

Maheshwari Reddy


2 Answers

This layout works in my app. The trick is to set these two attributes in ScrollView: android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent"

The simplified layout from my app:

<?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"     android:theme="@style/ThemeOverlay.AppCompat.Light">      <RelativeLayout         android:id="@+id/linear"         android:layout_width="0dp"         android:layout_height="56dp"         android:background="@color/title"         app:layout_constraintLeft_toLeftOf="parent"         app:layout_constraintRight_toRightOf="parent"         app:layout_constraintTop_toTopOf="parent" />      <ScrollView         android:layout_width="0dp"         android:layout_height="0dp"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintLeft_toLeftOf="parent"         app:layout_constraintRight_toRightOf="parent"         app:layout_constraintTop_toBottomOf="@id/linear">          <android.support.constraint.ConstraintLayout             android:layout_width="match_parent"             android:layout_height="wrap_content">              <TextView                 android:id="@+id/titleView"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_marginLeft="8dp"                 android:layout_marginStart="8dp"                 android:text="@string/title"                 android:textSize="14sp"                 app:layout_constraintBaseline_toBaselineOf="@+id/title"                 app:layout_constraintLeft_toLeftOf="parent" />              <EditText                 android:id="@+id/title"                 android:layout_width="0dp"                 android:layout_height="wrap_content"                 android:layout_marginEnd="8dp"                 android:layout_marginRight="8dp"                 android:hint="toilet title"                 android:inputType="text"                 android:textColor="@android:color/holo_red_dark"                 android:textSize="12sp"                 app:layout_constraintLeft_toLeftOf="@+id/open_hour"                 app:layout_constraintLeft_toRightOf="@+id/titleView"                 app:layout_constraintRight_toRightOf="parent"                 app:layout_constraintTop_toTopOf="parent" />             ...             Other Views in ScrollView             ...         </android.support.constraint.ConstraintLayout>     </ScrollView> </android.support.constraint.ConstraintLayout> 
like image 126
ping li Avatar answered Sep 19 '22 02:09

ping li


In my case NestedScrollView worked instead of ScrollView. Following is the snippet of my working layout:

<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">      <!-- Some Views Here -->      <android.support.v4.widget.NestedScrollView         android:layout_width="0dp"         android:layout_height="0dp"         android:fillViewport="true"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintLeft_toLeftOf="parent"         app:layout_constraintRight_toRightOf="parent"         app:layout_constraintTop_toBottomOf="@+id/view">          <android.support.constraint.ConstraintLayout             android:layout_width="match_parent"             android:layout_height="wrap_content">              <!-- Some Views That can be Scrolled Here -->          </android.support.constraint.ConstraintLayout>      </android.support.v4.widget.NestedScrollView>  </android.support.constraint.ConstraintLayout> 
like image 41
Firoz Memon Avatar answered Sep 20 '22 02:09

Firoz Memon