[英]Toolbar not visible in collapsed state inside CollapsingToolbarLayout
I have a ViewPager inside CollapsingToolbarLayout. 我在CollapsingToolbarLayout中有一个ViewPager。 When I scroll up the viewpager scrolls as normal but when it is collapsed the toolbar should be visible but it seems it stays behind the viewpager as I can see the snapping of the toolbar when I scroll up.
当我向上滚动viewpager时,它可以正常滚动,但是当它折叠时,工具栏应该是可见的,但是它似乎停留在viewpager的后面,因为我向上滚动时可以看到工具栏的对齐。 I have gone through several discussions on stackoverflow but didn't find the solution.
我已经对stackoverflow进行了多次讨论,但没有找到解决方案。 Please help me to identify what I'm missing here.
请帮助我确定我在这里缺少什么。
[ [
][10][
] [10] [
][10]
] [10]
This is my layout xml - 这是我的布局xml-
<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:background="@color/colorAppBg"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="300dp"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolBarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|snap|enterAlways"
app:scrimAnimationDuration="200"
app:scrimVisibleHeightTrigger="@dimen/scrimTrigger">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="@dimen/actionBarElevation"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax">
<android.support.v4.view.ViewPager
android:id="@+id/locationPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax"/>
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/locationPagerIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="8dp"
app:fillColor="@color/colorText"
app:layout_collapseMode="parallax"
app:pageColor="@color/colorText"
app:radius="3dp"
app:strokeWidth="0dp"/>
</FrameLayout>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
<TextView
android:id="@+id/titleView"
style="@style/TextViewNormal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="@color/colorPrimary"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="8dp"
android:padding="10dp"
android:text="hh"
android:textColor="@android:color/white"
android:textSize="20sp"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Try this in your code .It worked ok in my code . 在您的代码中尝试一下。在我的代码中效果很好。
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="256dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<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:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="@dimen/actionBarElevation"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax">
<!-- add your code here -->
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:id="@+id/titleView"
style="@style/TextViewNormal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="@color/colorPrimary"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
I found the problem. 我发现了问题。 The problem was
问题是
android:elevation="@dimen/actionBarElevation"
in FrameLayout 在FrameLayout中
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="@dimen/actionBarElevation"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax">
It is working as expected after removing this line of code. 删除此行代码后,它可以按预期工作。 But I don't know what is the problem with this.
但是我不知道这是什么问题。 However I get warning in editor saying Attribute elevation is only used in API level 21 and higher.
但是我在编辑器中收到警告,说属性提升仅在API级别21和更高版本中使用。 I don't think it should create any problem as I'm running the app in device which has the api level 25. and the app's target sdk is 26 and min sdk is 16.
我认为在api级为25的设备中运行应用程序时,它不会造成任何问题。应用程序的目标sdk是26,最小sdk是16。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.