折叠工具栏布局在滚动时不会消失

时间:2018-04-14 15:41:37

标签: android material-design toolbar android-collapsingtoolbarlayout

我是Android开发新手,我想实现如下布局:

enter image description here

但我遇到了一个大问题

enter image description here

所以我在协调器布局和appbarlayout里面发生了一个崩溃的工具栏布局,里面是工具栏和约束布局 当折叠工具栏布局消失时,布局的某些部分是可见的 我该如何解决这个问题?

这是我的.xml文件

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="@dimen/_1sdp"
    android:paddingBottom="@dimen/_20sdp">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

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

            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/bg_screen4"
                app:layout_collapseMode="pin"/>

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

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">`

这是标题布局:

<?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="wrap_content"
    android:elevation="@dimen/_1sdp"
    app:layout_collapseMode="parallax"
    app:layout_collapseParallaxMultiplier="0.3"
    android:layout_marginTop="@dimen/_56sdp"
    android:paddingBottom="@dimen/_20sdp">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/constraintLayout3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_collapseMode="parallax"
        android:background="@color/bgBottomNavigation"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        android:layout_marginBottom="8dp"
        app:layout_constraintVertical_bias="0.0">

        <android.support.constraint.Guideline
            android:id="@+id/guideline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_begin="170dp" />

        <TextView
            android:id="@+id/textView11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_32sdp"
            android:text="بیشعوری"
            android:textColor="#fff"
             app:layout_constraintBottom_toTopOf="@+id/textView12"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:layout_constraintLeft_creator="1"
            android:layout_marginLeft="64dp"
            app:layout_constraintRight_toLeftOf="@+id/guideline"
            android:layout_marginRight="8dp" />

        <TextView
            android:id="@+id/textView12"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_8sdp"
            android:text="اثر خاویر کرمنت"
            android:textColor="#fff"
            android:layout_marginLeft="@dimen/_20sdp"
            app:layout_constraintBottom_toTopOf="@+id/divider1"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView11"
            tools:layout_constraintLeft_creator="1"
            app:layout_constraintRight_toLeftOf="@+id/guideline"
            android:layout_marginRight="8dp" />

        <View
            android:id="@+id/divider1"
            android:layout_width="0dp"
            android:layout_height="@dimen/_4sdp"
            android:layout_marginTop="@dimen/_8sdp"
            app:layout_constraintBottom_toTopOf="@+id/ratingBar5"
            app:layout_constraintEnd_toEndOf="@+id/textView12"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginLeft="8dp"
            app:layout_constraintTop_toBottomOf="@+id/textView12"
            tools:layout_constraintLeft_creator="1"
            tools:layout_constraintRight_creator="1"
            app:layout_constraintRight_toLeftOf="@+id/guideline"
            app:layout_constraintHorizontal_bias="0.228"
            android:layout_marginRight="0dp" />

        <RatingBar
            android:id="@+id/ratingBar5"
            style="@style/Widget.AppCompat.RatingBar.Small"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/_8sdp"
            android:layout_marginTop="@dimen/_8sdp"
            android:layout_marginLeft="@dimen/_20sdp"
            app:layout_constraintBottom_toTopOf="@+id/textView15"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/divider1"
            tools:layout_constraintLeft_creator="1"
            app:layout_constraintRight_toLeftOf="@+id/guideline"
            android:layout_marginRight="8dp" />

        <TextView
            android:id="@+id/textView15"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/_40sdp"
            android:layout_marginTop="@dimen/_8sdp"
            android:text="تاریخ انتشار 1397/01/20"
            android:textColor="#fff"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/ratingBar5"
            tools:layout_constraintLeft_creator="1"
            android:layout_marginLeft="0dp"
            app:layout_constraintRight_toLeftOf="@+id/guideline"
            android:layout_marginRight="8dp"
            app:layout_constraintHorizontal_bias="0.523" />

    </android.support.constraint.ConstraintLayout>

    <ImageView
        android:id="@+id/img"
        android:layout_width="@dimen/_130sdp"
        android:layout_height="@dimen/_200sdp"
        android:layout_marginBottom="@dimen/_8sdp"
        android:layout_marginLeft="@dimen/_8sdp"
        android:layout_marginRight="@dimen/_8sdp"
        android:scaleType="fitXY"
        android:src="@drawable/bishori"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.923"
        app:layout_constraintLeft_toLeftOf="@+id/constraintLayout3"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/constraintLayout3"
        app:layout_constraintVertical_bias="0.060000002" />

    <Button
        android:id="@+id/button6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/_8sdp"
        android:layout_marginRight="@dimen/_8sdp"
        android:layout_marginTop="@dimen/_8sdp"
        android:elevation="1dp"
        android:text="مطالعه کتاب"
        app:layout_constraintBottom_toBottomOf="@+id/constraintLayout3"
        app:layout_constraintHorizontal_bias="0.12"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="@+id/constraintLayout3"
        app:layout_constraintTop_toBottomOf="@+id/constraintLayout3"
        app:layout_constraintVertical_bias="0.517"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />

</android.support.constraint.ConstraintLayout>`

感谢您的回答

0 个答案:

没有答案