NestedScrollView中的Android约束布局渲染问题

Off*_*set 3 java android android-layout

我试图将我的ConstraintLayout添加到NestedScrollView.在观看我的ContraintLayout时,一切看起来都很好.

但是然后将布局包含到我的NestedScrollView中会折叠ContraintLayout.(即使我在include和我的CL中使用匹配父宽度/ heigt)

这实际上是之前版本的ContraintLayout(~pre Beta)中的一个错误.Google Bug报告

我正在使用Verion beta4的这种方法.链接到Youtube AndroidDev频道

constraint_layout.xml:

<android.support.design.widget.CoordinatorLayout 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/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="de.project.andy.aliver.JobCreatorActivity">

    <include layout="@layout/content_job_creator" />

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="145dp"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="143dp"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/jc_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:drawable/arrow_up_float"
        android:layout_gravity="end|bottom"
        app:fabSize="normal"
        android:layout_margin="15dp" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

nested_scrollview_layout.xml:

<android.support.v4.widget.NestedScrollView 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="de.project.andy.aliver.JobCreatorActivity"
    tools:showIn="@layout/activity_job_creator">

    <include layout="@layout/constraint_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

有解决方法吗?

Off*_*set 12

天啊......没有答案就要研究一个小时.创建SO帖子并在5分钟后找到答案.

上面描述的这个问题与ScrollView中的相同.解决方案是添加

android:fillViewport="true"
Run Code Online (Sandbox Code Playgroud)

到可滚动的父级.

所以nested_scrollview_layout.xml将是:

<android.support.v4.widget.NestedScrollView 
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:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="de.project.andy.aliver.JobCreatorActivity"
tools:showIn="@layout/activity_job_creator">

<include layout="@layout/constraint_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)