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

前端 未结 10 1313
予麋鹿
予麋鹿 2020-12-03 02:34

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\

相关标签:
10条回答
  • 2020-12-03 03:07

    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>
    
    0 讨论(0)
  • 2020-12-03 03:10

    You have two solutions for this problem (the same solution but in two ways to do it):

    1. If you put the Design mode in Android Studio, select your ScrollView and open attributes tab and in the layout_height, select "match_constraint".

    2. If you use the Text mode in Android Studio, use this:

      <ScrollView
      android:layout_width="match_parent"
      android:layout_height="0dp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintTop_toBottomOf="@id/tb_details">
      

    See that the ScrollView height is set to 0dp. Both of this ways resolve the same problem but these are the different ways to do it.

    The ScrollView is not the root view, I have a Constraint layout wrapping the ScrollView as you.

    0 讨论(0)
  • 2020-12-03 03:22

    For me, I needed to add a LinearLayout inside my ScrollView in order to constrain it

    <androidx.constraintlayout.widget.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">
    
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="parent"
            tools:layout_editor_absoluteX="1dp">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                <View....</View>
    
            </LinearLayout>
    
        </ScrollView>
    
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    
    0 讨论(0)
  • 2020-12-03 03:26

    Just Put android:fillViewport="true" in Parent Layout

    0 讨论(0)
  • 2020-12-03 03:26

    I have resolve this issue. Inside ScrollView you can not use constraint Layout. for using constrain inside scroll u have to use Relative layout is parent of constraint Layout..

    so ur sequence should be:

    ScrollView ---> Relative Layout ---> Constraint Layout

    0 讨论(0)
  • 2020-12-03 03:27

    In my case, I had a tall TextView (height set to wrap_content) inside a ScrollView (height set to 0dp and being constraint on the top and bottom). No suggestions worked, but I solved the problem by wrapping the TextView inside a FrameLayout (height set to wrap_content).

    0 讨论(0)
提交回复
热议问题