【问题标题】:Anchor image gets overlapped by toolbar when CollapsingToolbarLayout is collapsed当 CollapsingToolbarLayout 折叠时,锚点图像被工具栏重叠
【发布时间】:2017-09-22 06:00:41
【问题描述】:

我在我的一个布局中使用了 CollapsingToolbarLayout,我在 AppBar 布局上锚定了一个图像 (id=event_logo); How it looks before collapsing

但是,当 CollapsingToolbarLayout 完全折叠时,工具栏会覆盖图像。 How it looks after collapsing

我的xml代码

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

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

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="fill"
                    android:fitsSystemWindows="true"
                    android:scaleType="center"
                    android:src="@drawable/bgg" />

                <android.support.v7.widget.Toolbar
                    android:id="@+id/about_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:theme="@style/MyTheme1"
                    app:layout_collapseMode="pin"
                    app:layout_scrollFlags="scroll|enterAlways"
                    app:popupTheme="@style/AppTheme.PopupOverlay" />

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

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

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

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

        <ImageView
            android:id="@+id/event_logo"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center_vertical|left"
            android:layout_margin="@dimen/fab_margin"
            android:src="@drawable/barcode_scanner"
            android:layout_marginTop="120dp"
            android:contentDescription="event_logo"
            app:layout_anchor="@+id/app_bar"
            app:layout_anchorGravity="bottom|right" />

在 Android 6.0 上测试

知道为什么会这样吗?

【问题讨论】:

    标签: android xml


    【解决方案1】:

    对于这个问题的未来读者......解决这个问题的诀窍是将高度设置为 20dp

    只需将高程属性添加到锚定图像

    <ImageView
                android:id="@+id/event_logo"
                android:layout_width="65dp"
                android:layout_height="65dp"
                android:layout_margin="@dimen/fab_margin"
                android:contentDescription="event_logo"
                android:elevation="20dp"
                android:scaleType="fitXY"
                app:layout_anchor="@+id/app_bar"
                app:layout_anchorGravity="bottom|right"
                tools:targetApi="lollipop" />

    注意:属性提升仅用于 API 21 及更高版本,这就是为什么需要添加 targetApi lollipop

    【讨论】:

    • 必须为高程设置的最小值是 4dp。在此之下,它开始与图像重叠。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 2016-07-20
    • 2017-02-21
    • 2016-04-10
    相关资源
    最近更新 更多