约束布局中的滚动查看不滚动到父约束的底部

约束布局中的滚动查看不滚动到父约束的底部

问题描述:

我有一个大约有12/13个字段的表单。我在约束布局中使用了Scrollview。以下是XML布局的层次结构。问题是,它不滚动到底部,而是滚动到第一个最初的10个视图。最后3个字段被隐藏,因为视图不再滚动。约束布局中的滚动查看不滚动到父约束的底部

父布局的

<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> 
+0

尝试将'ScrollView'的'android:layout_height'参数更改为'match_parent'。 – Ircover

+1

尝试过,但它不起作用。 –

+0

设置高度以匹配parent和fillViewPort为您的滚动视图为true,或尝试嵌套SCrollview –

这种布局工作在我的应用程序。 关键是要设置滚动型这两个属性: 机器人:layout_height = “0dp” 应用:layout_constraintBottom_toBottomOf = “父”

从我的应用程序的简化布局:

<?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> 

两步

用于滚动视图
  1. 保持布局高度零
    android:layout_height="0dp"

  2. 再次为滚动视图
    android:fillViewport="true"

尝试增加底部约束滚动型(如:app:layout_constraintBottom_toBottomOf="parent") 和改变机器人:layout_height = “WRAP_CONTENT” 到android:layout_height="0dp"

在工作我的情况NestedScrollView而不是ScrollView。以下是我的工作布局的片段:

<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>