【问题标题】:AppBarLayout not collapsing completely and expanding only partially until scroll reaches the topAppBarLayout 没有完全折叠并且仅部分扩展,直到滚动到达顶部
【发布时间】:2016-09-29 00:48:20
【问题描述】:

所以我有一个带有 AppBarLayout 和 CollapsingToolbarLayout 的 CoordinatorLayout。这是展开(左图)和折叠(右图)时的样子

我遇到的第一个问题是,当我向下滚动包含两个文本视图的蓝色 FrameLayout 时,它不会折叠。我想要的是只有工具栏在完全折叠时才可见。我尝试了一些事情,比如更改滚动标志和移动视图和视图组,但没有成功。这是 xml,我还将 windowTranslucentStatus 设置为 true,工具栏标题设置为空。

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>

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

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

        <ImageView
            android:id="@+id/main.imageview.placeholder"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:scaleType="centerCrop"
            android:src="@drawable/material_flat"
            app:layout_collapseMode="parallax"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:title=""
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:layout_collapseMode="pin"
            />
    </android.support.design.widget.CollapsingToolbarLayout>


    <FrameLayout
        android:id="@+id/main.framelayout.title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:background="?colorPrimary"
        android:orientation="vertical"
        app:layout_scrollFlags="scroll|enterAlways"
        >

        <LinearLayout
            android:id="@+id/main.linearlayout.title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="vertical"
            >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:gravity="bottom|center"
                android:text="Information"
                android:textColor="@android:color/white"
                android:textSize="30sp"
                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="4dp"
                android:text="Tagline"
                android:textColor="@android:color/white"
                />

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

<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="yu.heetae.android.materialdesign.ScrollingActivity"
    tools:showIn="@layout/activity_scrolling">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/text_margin"
        android:text="@string/large_text"/>

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

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    app:layout_anchor="@id/main.framelayout.title"
    app:layout_anchorGravity="top|end"
    app:srcCompat="@android:drawable/ic_dialog_email"/>

我遇到的第二个问题是,当向上滚动时,图像视图会扩展其高度的 60%,然后当滚动到顶部时,最后 40% 会扩展。我想要发生的是让图像视图在滚动后完全展开而不是部分展开。下面是一些有助于解释它的图像。左图是您正常向上滚动时的图像,右图是您最终向上滚动时的图像。

【问题讨论】:

    标签: android material-design android-coordinatorlayout android-appbarlayout android-collapsingtoolbarlayout


    【解决方案1】:

    我遇到了类似的工具栏部分打开的问题。我将 snap 添加到 scroll_flags 标签。我希望这就是你要问的。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-04
      • 1970-01-01
      • 1970-01-01
      • 2018-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多