【问题标题】:Parallax mode is not working in collapsing toolbar layout视差模式在折叠工具栏布局中不起作用
【发布时间】:2016-05-24 07:47:45
【问题描述】:

我正在设置折叠工具栏布局。我已经为工具栏下方的相对布局设置了视差模式。

但是当我向上滚动工具栏时它不会褪色。我只是在工具栏标题上方显示相对布局。它与工具栏合并。

已设置所有模式,但它仍在合并。

布局:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="160dp"
    android:id="@+id/appbar"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

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

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

            <RelativeLayout
                android:id="@+id/content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="30dp"
                app:layout_collapseMode="parallax"
                android:layout_gravity="bottom"
                android:layout_marginBottom="10dp"
                app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">


                <TextView
                    android:id="@+id/eventName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:text="Event Name"
                    android:textColor="#ffffff"
                    android:textSize="14sp"/>

                <TextView
                    android:id="@+id/date"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/eventName"
                    android:layout_marginTop="10dp"
                    android:text="Date"
                    android:textColor="#ffffff"
                    android:textSize="14sp"/>

                <TextView
                    android:id="@+id/time"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/date"
                    android:layout_marginBottom="10dp"
                    android:layout_marginTop="10dp"
                    android:text="Time"
                    android:textColor="#ffffff"
                    android:textSize="14sp"/>

            </RelativeLayout>


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

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

<android.support.v4.widget.NestedScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">


        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="false"
            android:layout_alignParentStart="false"
            android:layout_below="@+id/textView6"
            android:layout_marginTop="20dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="PLAN"
                android:layout_centerHorizontal="true"
                android:textAppearance="@android:style/TextAppearance.Large"
                android:id="@+id/textView6"
                android:layout_marginTop="10dp"
                android:layout_gravity="center_horizontal" />
            <Button
                android:layout_width="150dp"
                android:layout_height="40dp"
                style="?android:attr/borderlessButtonStyle"
                android:text="Schedule"
                android:id="@+id/schedule"
                android:layout_gravity="center_horizontal"
                android:background="@drawable/list_background"
                android:layout_marginTop="20dp" />

            <Button
                android:layout_width="150dp"
                android:layout_height="40dp"
                style="?android:attr/borderlessButtonStyle"
                android:text="Check List"
                android:id="@+id/button4"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:background="@drawable/list_background" />

            <Button
                android:layout_width="150dp"
                android:layout_height="40dp"
                android:text="Vendors"
                style="?android:attr/borderlessButtonStyle"
                android:id="@+id/button5"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:background="@drawable/list_background" />

            <Button
                android:layout_width="150dp"
                android:layout_height="40dp"
                android:text="Invitee"
                style="?android:attr/borderlessButtonStyle"
                android:id="@+id/button6"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:background="@drawable/list_background" />
        </LinearLayout>


</android.support.v4.widget.NestedScrollView>

向上滚动后看起来像这样:

怎么了?

请帮忙谢谢..

【问题讨论】:

  • 添加 CoordinatorLayout 作为你的父布局。
  • 你能分享屏幕吗?
  • 我已将协调器布局添加为父布局,不知道为什么它没有发布@PiyushGupta
  • 查看此链接blog.grafixartist.com/…
  • 请检查添加的屏幕。 @jaydroider

标签: android android-layout parallax android-collapsingtoolbarlayout


【解决方案1】:

尝试从您的Relative Layout 中删除enterAlways

Only use this.

app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

对于例如LayoutToolBar应该低于Relative Layout

<RelativeLayout
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:background="@drawable/header"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop">

            <ImageView
                android:id="@+id/imageViewPhoto"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:layout_centerInParent="true"
                app:layout_collapseMode="parallax" />

            <TextView
                android:id="@+id/textViewName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="false"
                android:layout_below="@+id/imageViewPhoto"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:text="TEXT"
                android:textSize="16dp" />

        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:fitsSystemWindows="true"
            android:gravity="top"
            app:layout_collapseMode="pin"
            app:layout_scrollFlags="scroll|enterAlways">

            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textSize="20dp"
                android:textStyle="bold" />
        </android.support.v7.widget.Toolbar>

【讨论】:

  • 知道了。我在相对布局上方添加了工具栏,应该在布局下方。 @jaydroider
  • 是的,它应该低于Tool Bar Layout
  • @user6265109 编辑了我的答案,请参考。
  • @user6265109 如果可行,则接受并投票赞成答案,这样问题将被关闭。
【解决方案2】:

在您的相对布局中添加以下行:

app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    相关资源
    最近更新 更多