[英]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.