簡體   English   中英

AppBarLayout不會完全折疊並且僅部分擴展直到滾動到達頂部

[英]AppBarLayout not collapsing completely and expanding only partially until scroll reaches the top

所以我有一個帶有 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"/>

我遇到的第二個問題是,當向上滾動時,imageview 會擴展其高度的 60% 左右,然后當滾動到達頂部時,最后 40% 會擴展。 我想要發生的是圖像視圖在滾動后完全展開而不是部分展開。 下面是一些有助於解釋它的圖像。 左圖是您正常向上滾動時的圖像,而右圖是您最終向上滾動到頂部時的圖像。

在此處輸入圖片說明 在此處輸入圖片說明

我遇到了部分打開工具欄的類似問題。 我在 scroll_flags 標簽中添加了 snap。 我希望這就是你要問的。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM