约束布局内

时间:2017-09-26 19:12:56

标签: android android-layout scrollview android-constraintlayout

我是我的搜索,最接近的问题是:Scrollview inside constraint layout does not scroll to the bottom of the parent constraint

但是没有解决方案 = |。

我正在尝试做什么:

我有一个约束布局,包含3个“部分”:顶部栏中间内容底部按钮

我想仅为中间内容设置一个scrollview。因此,如果您向下和向上滚动,则会连续看到顶栏底部按钮

但是这个滚动视图不起作用,我认为是与scrollview中的“match_parent”相关的东西,但我不能放这个选项,因为 scrollview Constraint中布局大小应该是相对的,如果我把匹配父级,它不会填充所有空格。

我已经在使用: fillViewport = “真”, layout_constraintBottom_toBottomOf = “父”

按照代码滚动视图名称:“scrollview2”

<?xml version="1.0" encoding="utf-8"?>

<!--Create by Canato 26/09/2017-->

<com.flipboard.bottomsheet.BottomSheetLayout 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/needs_search_bottomsheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:layout_editor_absoluteY="25dp"
    tools:layout_editor_absoluteX="0dp">

    <android.support.constraint.Guideline
        android:id="@+id/horGuideline10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.1"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="82dp" />

    <android.support.constraint.Guideline
        android:id="@+id/horGuideline90"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.9"
        tools:layout_editor_absoluteY="536dp"
        tools:layout_editor_absoluteX="0dp" />

    <include
        android:id="@+id/actionbar"
        layout="@layout/view_actionbar"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/horGuideline10"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />

    <Button
        android:id="@+id/needs_search_save_btn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/btn_green_bright_half_round_selector"
        android:gravity="center"
        android:text="@string/str_continue_save"
        android:textAllCaps="false"
        android:textColor="@color/WHITE"
        android:textSize="@dimen/size_text_button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/horGuideline90"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1" />

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="0dp"
        android:layout_marginTop="0dp"
        android:fillViewport="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/horGuideline10">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="400dp">


            <android.support.constraint.Guideline
                android:id="@+id/verGuideline20"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_percent="0.2"
                tools:layout_editor_absoluteX="72dp"
                tools:layout_editor_absoluteY="206dp" />

            <android.support.constraint.Guideline
                android:id="@+id/verGuideline55"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_percent="0.55"
                tools:layout_editor_absoluteX="198dp"
                tools:layout_editor_absoluteY="206dp" />

            <android.support.constraint.Guideline
                android:id="@+id/verGuideline90"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_percent="0.9"
                tools:layout_editor_absoluteX="324dp"
                tools:layout_editor_absoluteY="206dp" />

            <android.support.constraint.Guideline
                android:id="@+id/horGuideline10in"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_percent="0.1"
                tools:layout_editor_absoluteX="0dp"
                tools:layout_editor_absoluteY="233dp" />

            <android.support.constraint.Guideline
                android:id="@+id/horGuideline20"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_percent="0.2"
                tools:layout_editor_absoluteX="0dp"
                tools:layout_editor_absoluteY="260dp" />

            <android.support.constraint.Guideline
                android:id="@+id/horGuideline28"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_percent="0.28"
                tools:layout_editor_absoluteX="0dp"
                tools:layout_editor_absoluteY="282dp" />

            <android.support.constraint.Guideline
                android:id="@+id/horGuideline38"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_percent="0.38"
                tools:layout_editor_absoluteX="0dp"
                tools:layout_editor_absoluteY="309dp" />

            <TextView
                android:id="@+id/needs_search_title_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginStart="16dp"
                android:text="@string/service_request_title_text"
                android:textColor="@color/ANDROID_DARK_GRAY"
                android:textSize="@dimen/title_text_size"
                app:layout_constraintBaseline_toBaselineOf="@+id/needs_search_title_edit"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/verGuideline20" />

            <EditText
                android:id="@+id/needs_search_title_edit"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginTop="8dp"
                android:ems="10"
                android:hint="@string/service_request_title_explanation_text"
                android:inputType="textPersonName"
                android:textColorHint="@color/ANDROID_DARK_GRAY"
                app:layout_constraintBottom_toTopOf="@+id/horGuideline10in"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="@+id/verGuideline20"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />

            <ImageView
                android:id="@+id/iconLocation"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginBottom="8dp"
                android:layout_marginLeft="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:contentDescription="@string/service_request_location_icon_contentDescription"
                app:layout_constraintBottom_toTopOf="@+id/horGuideline20"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/verGuideline20"
                app:layout_constraintTop_toTopOf="@+id/horGuideline10in"
                app:layout_constraintVertical_bias="0.454"
                app:srcCompat="@drawable/ic_location_on_gray_24dp" />

            <EditText
                android:id="@+id/service_request_address_editText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginTop="8dp"
                android:ems="10"
                android:hint="@string/service_request_location_text"
                android:inputType="textPersonName"
                android:textColorHint="@color/ANDROID_DARK_GRAY"
                android:textSize="@dimen/size_text_button"
                app:layout_constraintLeft_toRightOf="@+id/iconLocation"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="@+id/horGuideline10in" />

            <ImageView
                android:id="@+id/iconDecribeText"
                android:layout_width="0dp"
                android:layout_height="0dp"

                android:layout_marginLeft="16dp"
                android:layout_marginStart="16dp"
                android:contentDescription="@string/service_request_text_contentDescription"
                app:layout_constraintBottom_toTopOf="@+id/horGuideline38"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/verGuideline20"
                app:layout_constraintTop_toTopOf="@+id/horGuideline28"
                app:srcCompat="@drawable/ic_short_text_gray_24dp" />

            <EditText
                android:id="@+id/needs_search_description_edit"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginTop="8dp"
                android:ems="10"
                android:hint="@string/service_request_small_text_explanation"
                android:inputType="textMultiLine"
                android:textColorHint="@color/ANDROID_DARK_GRAY"
                android:textSize="@dimen/size_text_button"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="@+id/verGuideline20"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="@+id/horGuideline28" />

            <Button
                android:id="@+id/needs_search_address_locate_btn"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:alpha="0.5"
                android:background="@android:drawable/dialog_holo_light_frame"
                app:layout_constraintBottom_toTopOf="@+id/horGuideline28"
                app:layout_constraintLeft_toLeftOf="@+id/verGuideline20"
                app:layout_constraintRight_toLeftOf="@+id/verGuideline55"
                app:layout_constraintTop_toTopOf="@+id/horGuideline20"
                app:layout_constraintVertical_bias="0.0" />

            <Button
                android:id="@+id/needs_search_address_home_btn"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginEnd="8dp"
                android:layout_marginRight="8dp"
                android:alpha="0.5"
                android:background="@android:drawable/dialog_holo_light_frame"
                app:layout_constraintBottom_toTopOf="@+id/horGuideline28"
                app:layout_constraintLeft_toLeftOf="@+id/verGuideline55"
                app:layout_constraintRight_toLeftOf="@+id/verGuideline90"
                app:layout_constraintTop_toTopOf="@+id/horGuideline20"
                app:layout_constraintVertical_bias="0.0" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/needs_search_images_recyclerview"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginBottom="0dp"
                android:layout_marginEnd="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="24dp"
                android:focusable="false"
                android:focusableInTouchMode="false"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/needs_search_description_edit"
                tools:listitem="@layout/needs_search_big_image_list_item" />

        </android.support.constraint.ConstraintLayout>
    </ScrollView>

</android.support.constraint.ConstraintLayout>

</com.flipboard.bottomsheet.BottomSheetLayout>

2 个答案:

答案 0 :(得分:2)

好吧,我刚刚和朋友找到了解决方案,首先我考虑删除这个,但是因为其他人可能会遇到同样的问题是解决方案:

我只是删除所有指南并重新构建,连接元素时不使用这么多指南。

有点幸运,因为我在改变方向时这样做了。

答案 1 :(得分:1)

您需要使用以下约束

创建chain
    顶栏中的
  • app:layout_constraintBottom_toTopOf="@+id/scrollView2" app:layout_constraintTop_toTopOf="parent"

  • 中间内容

    中的
  • app:layout_constraintBottom_toTopOf="@+id/needs_search_save_btn" app:layout_constraintTop_toBottomOf="@+id/actionbar"

  • 底部按钮中的
  • app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toBottomOf="@+id/scrollView2"