简体   繁体   English

当CollapsingToolbarLayout折叠时,锚定图像会被工具栏重叠

[英]Anchor image gets overlapped by toolbar when CollapsingToolbarLayout is collapsed

I am using CollapsingToolbarLayout in one of my layouts, I anchored an image (id=event_logo) on AppBar layout; 我在一种布局中使用CollapsingToolbarLayout,将图像(id = event_logo)锚定在AppBar布局上; How it looks before collapsing 塌陷前的外观

however, when CollapsingToolbarLayout is totally collapsed the Toolbar covers the image. 但是,当CollapsingToolbarLayout完全折叠时,工具栏将覆盖图像。 How it looks after collapsing 塌陷后的外观

my xml code 我的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" /> 

Tested on Android 6.0 在Android 6.0上测试

Any Idea why is this the case? 知道为什么会这样吗?

For future readers to this question...The trick to solve this issue is to set elevation to 20dp 对于未来的读者来说...解决此问题的技巧是将仰角设置为20dp

Simply add elevation attribute to the anchored image 只需将高程属性添加到锚定图像

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

note: attribute elevation is used only for API 21 and higher, that's why it's necessary to add targetApi lollipop 注意:属性提升仅用于API 21及更高版本,这就是为什么必须添加targetApi棒棒糖的原因

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CollapsingToolbarLayout折叠时未显示工具栏标题 - Toolbar Title not showing when CollapsingToolbarLayout collapsed 当CollapsingToolbarLayout折叠时,工具栏HOME不起作用 - Toolbar HOME not working when CollapsingToolbarLayout collapsed 在 CollapsingToolbarLayout 中折叠时如何删除透明的工具栏填充 - How to remove transparent Toolbar padding when collapsed in CollapsingToolbarLayout 如何将CollapsingToolbarLayout的背景保留为ToolBar的背景,即使在折叠时也是如此 - How to keep the background of CollapsingToolbarLayout as the background of ToolBar even when collapsed 未折叠时,工具栏的某些部分在CollapsingToolbarLayout的ImageView上可见 - When not collapsed some part of the the toolbar is visible over the ImageView of CollapsingToolbarLayout 如何将RecyclerView放在CollapsingToolbarLayout下面并在Android中折叠时响应工具栏? - How to put RecyclerView below CollapsingToolbarLayout and responsive to toolbar when collapsed in Android? 即使 CollapsingToolbarLayout 折叠,如何使 Toolbar 和 TabLayout 仍然可见? - How to make Toolbar and TabLayout still visible even when CollapsingToolbarLayout is collapsed? 滚动时,CollapsingToolbarLayout未折叠 - CollapsingToolbarLayout not collapsed when scrolled 在CollapsingToolbarLayout中,工具栏在折叠状态下不可见 - Toolbar not visible in collapsed state inside CollapsingToolbarLayout CollapsingToolbarLayout 在工具栏android上带有图像 - CollapsingToolbarLayout with image on toolbar android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM