簡體   English   中英

奇怪的CoordinatorLayout / AppBarLayout行為

[英]Strange CoordinatorLayout/AppBarLayout behavior

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="200dp">

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

    <View
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@color/colorAccent"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom"/>

    <include layout="@layout/content_scrolling"/>
</android.support.design.widget.CoordinatorLayout>

似乎,一旦CollapsingToolbarLayout達到minHeight高度,AppBarLayout就會變成“ ontop”視圖。 看截圖:

問題1 :為什么會這樣?

問題2 :有可能防止這種情況發生嗎? 我需要在CollapsingToolbarLayout折疊到其最小高度時將正方形放在頂部。

我認為您AppBarLayout問題的原因是AppBarLayout的錨點和height屬性。 我建議做什么:

  • AppBarLayoutheight屬性設置為wrap_content

  • 將您的CollapsingToolbarLayoutmax_heightheight設置為200dp

  • View的錨點設置為CollapsingToolbarLayout

老實說,我希望我能提供幫助,但我對Android還是很陌生,但是如果我為您找到答案,請告訴我。 -丹尼爾

暫無
暫無

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

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